我正在尝试使用 codeigniter 3 上传图像文件,但它不起作用。无论我做什么,它总是说“您没有选择要上传的文件”。当我单击“网络”选项卡中的错误时,它会在控制台上记录错误 500,然后将我重定向到显示该错误的新选项卡。 这是我的 HTML 代码:
<div id="container">
<h1>Welcome to CodeIgniter!</h1>
<div id="body">
<form method="post" enctype="multipart/form-data" action="<?php echo base_url('index.php/welcome/upload'); ?>">
<input type="text" name="username" value="Zahid Saeed">
<input type="file" name="profile_img">
<button type="submit">Submit Form</button>
</form>
</div>
这是我的 Controller :
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->helper("url");
}
public function index()
{
$this->load->view('welcome_message');
}
public function upload() {
$config = array(
"upload_path" => "./uploads/",
"allowed_types" => "gif|jpg|png"
);
echo "<pre>";
print_r($this->input->post());
print_r($_FILES);
echo "</pre>";
$this->load->library("upload", $config);
$this->upload->initialize($config);
if(!$this->upload->do_upload("profile_img")) {
echo $this->upload->display_errors();
echo "IN IF";
}
else {
echo "img uploaded successfully";
}
}
}
还有一件事,确切的代码在 linux 机器上运行,实际上在服务器上运行。但它不适用于我的笔记本电脑。我正在使用 Windows 8.1
提前致谢
最佳答案
打开你的 php.ini 文件
搜索 extension=php_fileinfo.dll
如果你使用的是 xampp,它可能会被默认注释掉
change
;extension=php_fileinfo.dll
to
extension=php_fileinfo.dll
然后重启你的xampp...
这解决了我的问题
关于php - Codeigniter 文件上传问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40792479/