在本地工作,但在我尝试过的两台服务器上显示相同的错误消息。使用 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。
因此,即使代码全部正确,错误实际上是在 PHP 本身上。哑剧类型中存在拼写错误。
什么时候var_dump($_FILES)
它吐出来["type"]=> string(14) "aplication/pdf"
请注意,“应用程序”拼写错误。
检查了同事的机器和他的正确性,所以可能是 php >5.3.5 的问题
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)