$_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
です。
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
空です。