CodeIgniter上传类PDF文件类型不允许 [英] CodeIgniter Upload class PDF filetype not allowed
问题描述
在本地工作,但在两台服务器上,我尝试了相同的错误信息显示。使用Codeigniter 2.1.3
private function upload_file(){
$ config ['upload_path'] ='./上传/';
$ config ['allowed_types'] ='jpg | png | jpeg | gif | pdf';
$ config ['max_width'] ='0';
$ config ['max_height'] ='0';
$ config ['encrypt_name'] = true;
$ this-> load->库('upload',$ config);
var_dump($ _ FILES);
if(!$ this-> upload-> do_upload()){
$ error = array('error'=> $ this-> upload-> display_errors());
var_dump($ error);
die();
返回$错误;
} else {
$ data = array('upload_data'=> $ this-> upload-> data());
var_dump($ data);
die();
返回$ data;
$ b 在执行 var_dump( $ _FILES);
显示正确的信息
array(1){[userfile] => array(5){[name] =>字符串(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)
give off array(1){[error] =>字符串(64)您正在尝试上传的文件类型是不允许的。}
测试png和jpg,这些作品奇妙的是。
正确的mime类型在配置文件中 config / mimes.php
'pdf'=> array('application / pdf','application / x-download'),
编辑:意味着任何东西,本地服务器是一个MAC,两个遥控器是Windows。
错误实际上是在PHP本身。这里有个MIME类型的拼写错误。
当 var_dump($ _ FILES)
它吐出 [type] =>字符串(14)aplication / pdf
请注意,应用程序是拼写错误。
检查同事机器和他的正确,所以可能是PHP> 5.3.5
的问题Works locally but on the two servers I've tried the same error message is shown. Using 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;
}
}
While doing the var_dump($_FILES);
it shows the correct information
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)
giving off array(1) { ["error"]=> string(64) " The filetype you are attempting to upload is not allowed. " }
Tested with both a png and jpg and these works marvelously.
The correct mime-types are in the config file config/mimes.php
'pdf' => array('application/pdf', 'application/x-download'),
Edit: If it means anything, the local server is a MAC and the two remotes are windows.
解决方案 So even though the code is all correct the error is actually on PHP itself. There's a spelling mistake in there mime-types.
When var_dump($_FILES)
it spitting out ["type"]=> string(14) "aplication/pdf"
Note that "application" is spelt wrong.
Checked on workmates machine and his correct, so might be an issue with php >5.3.5
这篇关于CodeIgniter上传类PDF文件类型不允许的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!