CodeIgniter“您尝试上传的文件类型不被允许”。 [英] CodeIgniter "The filetype you are attempting to upload is not allowed."
问题描述
我在搜索很多,并发现很多问题,关于这个问题,不幸的是没有答案确实帮助我。
我试图上传一个png图像,我收到以下错误:
您尝试上传的文件类型不允许。
我遵循此CI指南来构建我的代码: http:/ /codeigniter.com/userguide/libraries/file_uploading.html
这是我得到的:
查看文件:
[..]
<?= form_open_multipart()?&
< input type =filename =userfilesize =20/>
< br />< br />
< input type =submitvalue =upload/>
<?= form_close()?>
[..]
我的控制器:
$ config ['upload_path'] ='./uploads/';
$ config ['allowed_types'] ='gif | jpg | png';
$ config ['max_size'] ='100';
$ config ['max_width'] ='1024';
$ config ['max_height'] ='768';
$ this-> load-> library('upload',$ config);
$ xx = array('upload_data'=> $ this-> upload-> data());
$ mimetype = $ xx ['upload_data'] ['file_type'];
var_dump('Mime:'。$ mimetype);
var_dump($ _ FILES);
if(!$ this-> upload-> do_upload())
{
注意:: add($ this-> upload-> display_errors ,'error');
}
else
{
$ data ['upload_data'] = $ this-> upload-> data();
}
正如你可以看到的,我尝试 var_dump
>看起来一切都很好: array(1){[userfile] = array(5){[name] => string(14)imageofm.png[type] => string(9)image / png[tmp_name] => string(18)/ var / tmp / php5cDAZJ[error] => int(0)[size] => int(358)}}
此外,我得到'png'=> ;在 config / mimes.php
中的数组('image / png','image / x-png'),
>
但是,它对所有图片都有效(尚未尝试其他扩展程序)。
帮助尝试。
解决方案只需编辑 application / config / mimes.php ,并将 csv 的行替换为
: csv'=> array('application / vnd.ms-excel','text / anytext','text / plain','text / x-comma-separated-values','text / comma-separated-values','application / octet -stream','application / vnd.ms-excel','application / x-csv','text / x-csv','text / csv','application / csv','application / excel' /vnd.msexcel')
I was searching a lot and found many questions regarding this problem, unfortunately none of answers did help me.
I'm trying to upload a png image, and I'm receiving the following error:
The filetype you are attempting to upload is not allowed.
I was following this CI guide to build my code: http://codeigniter.com/user_guide/libraries/file_uploading.html
Here is what I got:
view file:
[..]
<?= form_open_multipart() ?>
<input type="file" name="userfile" size="20" />
<br /><br />
<input type="submit" value="upload" />
<?= form_close() ?>
[..]
My controller:
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
$xx = array('upload_data' => $this->upload->data());
$mimetype= $xx['upload_data']['file_type'];
var_dump('Mime: ' . $mimetype);
var_dump($_FILES);
if ( !$this->upload->do_upload())
{
Notice::add($this->upload->display_errors(), 'error');
}
else
{
$data['upload_data'] = $this->upload->data();
}
As you can see I'm tryin to var_dump
the mime type and result is empty.
When I do var_dump($_FILES)
it looks like everything is fine:
array(1) { ["userfile"]=> array(5) { ["name"]=> string(14) "imageofm.png" ["type"]=> string(9) "image/png" ["tmp_name"]=> string(18) "/var/tmp/php5cDAZJ" ["error"]=> int(0) ["size"]=> int(358) } }
Also, I got 'png' => array('image/png', 'image/x-png'),
line, in my config/mimes.php
.
However, it does happend for all images (haven't tried yet other extensions).
I'd appreciate every help attempt.
解决方案 Just edit the mimes.php file in application/config/mimes.php and replace the line for the csv by this one:
'csv' => array('application/vnd.ms-excel', 'text/anytext', 'text/plain', 'text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel')
这篇关于CodeIgniter“您尝试上传的文件类型不被允许”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!