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.

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

报告相同问题?

悬赏问题

  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行