php – CodeIgniter“不允许您尝试上传的文件类型.”

前端之家收集整理的这篇文章主要介绍了php – CodeIgniter“不允许您尝试上传的文件类型.”前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我经常搜索并发现很多关于这个问题的问题,遗憾的是没有一个答案对我有帮助.

我正在尝试上传png图像,我收到以下错误

The filetype you are attempting to upload is not allowed.

我正在遵循此CI指南来构建我的代码http://codeigniter.com/user_guide/libraries/file_uploading.html

这是我得到的:

查看文件

  1. [..]
  2. <?= form_open_multipart() ?>
  3. <input type="file" name="userfile" size="20" />
  4. <br /><br />
  5. <input type="submit" value="upload" />
  6. <?= form_close() ?>
  7. [..]

我的控制器:

  1. $config['upload_path'] = './uploads/';
  2. $config['allowed_types'] = 'gif|jpg|png';
  3. $config['max_size'] = '100';
  4. $config['max_width'] = '1024';
  5. $config['max_height'] = '768';
  6.  
  7.  
  8. $this->load->library('upload',$config);
  9.  
  10. $xx = array('upload_data' => $this->upload->data());
  11. $mimetype= $xx['upload_data']['file_type'];
  12.  
  13. var_dump('Mime: ' . $mimetype);
  14. var_dump($_FILES);
  15.  
  16. if ( !$this->upload->do_upload())
  17. {
  18. Notice::add($this->upload->display_errors(),'error');
  19. }
  20. else
  21. {
  22. $data['upload_data'] = $this->upload->data();
  23. }

正如你所看到的,我正在尝试var_dump mime类型,结果为空.

当我做var_dump($_ FILES)时,看起来一切都很好:

  1. 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’=>数组(‘image / png’,’image / x-png’),line,在我的config / mimes.PHP中.

但是,它确实发生在所有图像上(还没有尝试过其他扩展).

我很感激每一次尝试.

只需编辑application / config / mimes.PHP中的mimes.PHP文件,并用以下内容替换csv的行:
  1. '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')

猜你在找的PHP相关文章