我在使用CodeIgniter 2.1.0上传文件时遇到问题,因为我收到$ _FILES数组为空。无法使用CodeIgniter 2.1.0上传文件
这是以下形式:
<form enctype="multipart/form-data" action="<?= base_url()?>nicUpload/test" method="POST">
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
在所呈现的形式的操作采用值:http://localhost/nicUpload/test
。
这是控制器:
<?php
class NicUpload extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->helper(array('form', 'url'));
}
function test() {
echo count($_FILES);
}
}
?>
结果是0
,我希望1
。
我尝试没有笨做同样的:
的index.php:
<!doctype html>
<html>
<head></head>
<body>
<form enctype="multipart/form-data" action="upload.php" method="POST">
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
</body>
</html>
upload.php的:
<?php
echo count($_FILES);
?>
,我得到预期的结果(1
)。所以这不是一个PHP配置问题。
**更新**
我应该早说过了,但是如果我使用CodeIgniter的文件上传类它CI的system/libraries/Upload.php
的这行失败:
// Is $_FILES[$field] set? If not, no reason to continue.
if (! isset($_FILES[$field]))
{
$this->set_error('upload_no_file_selected');
return FALSE;
}
为$_FILES
是空的。