我正在使用 codeigniter,当我尝试上传一些文本文件时发现了一个奇怪的情况。
使用指示(CI doc)的方法文档一切正常,但是如果我尝试上传包含字符串'//'(不带引号)的文件,我得到的结果是“不允许您尝试上传的文件类型。”
任何想法?
使用的代码:(控制器)
function do_upload() {
$config['upload_path'] = APPPATH.'uploads/';
$config['allowed_types'] = 'txt|csv';
$config['max_size'] = '1024';
$config['max_width'] = '0';
$config['max_height'] = '0';
$this->load->library('upload', $config);
@var_dump($_FILES['userfile']); // debug
if (!$this->upload->do_upload()) {
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
} else
echo "<br>upload ok";
}
upload_form.php(查看):
<?php
if (isset($error)) echo $error;
echo form_open_multipart('supervisor/do_upload');
echo form_label('File', 'userfile');
echo form_upload('userfile');
echo form_submit('submit', 'Upload');
echo form_close()
?>
例如:(.txt 用于上传)
[file1.txt]:
THIS IS A TEXT FILE # work fine
[file2.txt]:
THIS IS A // TEXT FILE # fail! note: {blank}//{blank}
输出(上传file1.txt)
array(5) { ["name"]=> string(9) "file1.txt" ["type"]=> string(10) "text/plain" ["tmp_name"]=> string(14) "/tmp/phpLVaMGs" ["error"]=> int(0) ["size"]=> int(19) }
upload ok
输出(上传file2.txt)
array(5) { ["name"]=> string(9) "file2.txt" ["type"]=> string(10) "text/plain" ["tmp_name"]=> string(14) "/tmp/phpFu4znR" ["error"]=> int(0) ["size"]=> int(22) }
The filetype you are attempting to upload is not allowed.
...
Firebug POST:(上传file2.txt)
userfile THIS IS A // TEXT FILE
submit Upload
Fuente
-----------------------------15028408581691128039842883428
Content-Disposition: form-data; name="userfile"; filename="file2.txt"
Content-Type: text/plain
THIS IS A // TEXT FILE
-----------------------------15028408581691128039842883428
Content-Disposition: form-data; name="submit"
Upload
-----------------------------15028408581691128039842883428--