【发布时间】:2012-06-18 17:36:35
【问题描述】:
我在使用 CodeIgniter 2.1.0 上传文件时遇到问题,因为我收到的 $_FILES 数组是空的。
这是表格:
<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。
我尝试在没有 CodeIgniter 的情况下做同样的事情:
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>
上传.php:
<?php
echo count($_FILES);
?>
我得到了预期的结果 (1)。所以不是php配置问题。
** 更新 **
我应该早点说,但如果我使用 CodeIgniter 的 Upload 类,它会在 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 是空的。
【问题讨论】:
标签: php codeigniter file-upload codeigniter-2