duanhao1004 2015-03-10 11:46
浏览 68
已采纳

使用Codeigniter上传获取“不允许文件类型”

First of all, there are already a lot of (solved) questions regarding this topic. And I tried all possible solutions. But to no avail.

  • The problem occurs in both CI versions 2.1.4 and 2.2.1.
  • I also tried using different filetypes, such as png,gif and txt.
  • I've done no mime-type alterations, eg. by using AddType in the .htaccess file
  • I've used a simple html form, and a Postman for debugging
  • I've tried it with both PHP versions 5.5 and 5.6 (fileinfo module enabled)
  • The mime types do exist in the mimes.php file
  • The tmp folder is writable

I'm out of options...
Does anybody know what the issue might be?

Thanks in advance!


configuration

$this->uploadconfig =  array(
    'upload_path'     => "./tmp/",
    'allowed_types'   => "png|gif|txt",
    'overwrite'       => TRUE,
    'max_size'        => "25000KB",
    'max_height'      => "5000",
    'max_width'       => "5000"
);
$this->load->library('upload', $this->uploadconfig);

error

The filetype you are attempting to upload is not allowed.

output

[file_name] => test.png
[file_type] => image/png
[file_path] => /CORRECT_SERVER_PATH/tmp/
[full_path] => /CORRECT_SERVER_PATH/tmp/test.png
[raw_name] => test
[orig_name] => 
[client_name] => test.png
[file_ext] => .png
[file_size] => 851
[is_image] => 1
[image_width] => 
[image_height] => 
[image_type] => 
[image_size_str] => 
  • 写回答

1条回答 默认 最新

  • donglian5309 2015-03-10 13:00
    关注

    I found the solution:

    Codeigniter 2.1.4 has a bug as described here.
    So I've update CI to version 2.2.1, folowing the update instrucions here and here.

    After checking the mimes.php file for a second time, I noticed a difference between my original file, and the one included in the newer version. I replaced the old one with the newer one, and the problem was solved.

    Not documented in the upgrade instructions, is the fact that there is a difference between both files. The older (CI 2.1.4) of the file returns an array. The newer one (CI 2.2.1) does not return an array, but sets an array with the variable name $mimes.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效