【发布时间】:2013-04-04 10:30:14
【问题描述】:
在本地工作,但在我尝试过的两台服务器上显示相同的错误消息。使用 Codeigniter 2.1.3
private function upload_file(){
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'jpg|png|jpeg|gif|pdf';
$config['max_width'] = '0';
$config['max_height'] = '0';
$config['encrypt_name'] = true;
$this->load->library('upload', $config);
var_dump($_FILES);
if ( ! $this->upload->do_upload()){
$error = array('error' => $this->upload->display_errors());
var_dump($error);
die();
return $error;
} else {
$data = array('upload_data' => $this->upload->data());
var_dump($data);
die();
return $data;
}
}
在执行var_dump($_FILES); 时,它会显示正确的信息
array(1) { ["userfile"]=> array(5) { ["name"]=> string(8) "0002.pdf" ["type"]=> string(14) "aplication/pdf" ["tmp_name"]=> string(27) "C:\Windows\Temp\php9454.tmp" ["error"]=> int(0) ["size"]=> int(29295) } }
var_dump($error) 放出array(1) { ["error"]=> string(64) " The filetype you are attempting to upload is not allowed. " }
使用 png 和 jpg 进行测试,效果非常好。
正确的 mime 类型在配置文件 config/mimes.php
'pdf' => array('application/pdf', 'application/x-download'),
编辑:如果它意味着什么,本地服务器是一个 MAC,两个远程是 windows。
【问题讨论】:
-
您确定将更改上传到服务器?我只是问,因为你说它在本地有效。
-
是的,我很肯定,这东西几个月前就涨了。刚刚停止工作,不知道什么时候。我还添加了 var_dumps() 并在远程服务器上进行了测试,所以它肯定有最新的代码
-
它只是随机停止工作?您可能需要查明是否有人对服务器、apache、php 配置文件或类似内容进行了任何更改。你能写一个不使用codeigniter的测试上传脚本,看看它是否允许你上传pdf文件吗?
-
服务器都运行 2.1.3? 2.1.0 中的上传类存在错误。
-
是的,两者都在运行 2.1.3,两台服务器上的代码完全相同。 @Danny 仍在尝试将脚本放在一起,在本地尝试,但它拒绝我上传 pdf...
标签: php codeigniter file-upload mime-types