Codeigniter:不允许您尝试上传的文件类型.昨天还好 [英] Codeigniter : The filetype you are attempting to upload is not allowed. Yesterday it was fine

查看:117
本文介绍了Codeigniter:不允许您尝试上传的文件类型.昨天还好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的codeigniter应用今天突然坏了.我没有处理上传代码,今天尝试上传图像时,突然出现不允许您尝试上传的文件类型".昨天一切都很好.

My codeigniter app suddenly broke today. I didn't work on the upload code and when I tried to upload an image today I suddenly got "The filetype you are attempting to upload is not allowed." Yesterday all was fine.

我的配置数组是:

$config = array(
     'file_name' => $data['slug'] .'-'. $key,
     'upload_path' => './images',
     'allowed_types' => 'gif|jpg|jpeg|png'
    );

我还尝试将允许的类型设置为:图像/gif |图像/jpg |图像/jpeg |图像/png",但没有运气.

I have also tried to set allowed types as : 'image/gif|image/jpg|image/jpeg|image/png' but no luck.

转储$ this-> upload-> data():

The dumping $this->upload->data() :

Array
(
    [file_name] => ring.jpg
    [file_type] => image/jpeg
    [file_path] => /home/user/www.domain.ca/images/
    [full_path] => /home/user/www.domain.ca/images/ring.jpg
    [raw_name] => ring
    [orig_name] => 
    [client_name] => ring.jpg
    [file_ext] => .jpg
    [file_size] => 49158
    [is_image] => 1
    [image_width] => 
    [image_height] => 
    [image_type] => 
    [image_size_str] => 
)

我知道以前版本的CI中存在一些错误,但是昨天我没有这些问题.我也知道,只有在MIME类型与允许的类型不匹配的情况下,才会发生此错误,但事实并非如此.

I understand that there were some bugs in previous versions of CI, but I didn't have these issues yesterday. I also understand that this error only occurs if the MIME type does not match what is allowed, but that does not seem to be the case.

服务器是Apache.

The server is Apache.

有人知道这可能是什么问题吗?谢谢!

Does anyone have any idea what could be the problem? Thanks!

推荐答案

我遇到过两次这个问题,这是对我有用的两个解决方案;

I've had this problem twice, here are the two solutions that have worked for me;

1-系统报告的mime类型可以变化,并且可能不在为特定文件扩展名设置的mime类型数组中. .csv文件是我为此发现的最糟糕的文件.在上传后转储上传数据,找出系统报告的MIME类型

1 - The mime type reported by the system can vary, and may not be in the array of mime types set for a particular file extension. .csv files are the worst I have found for this. Find out what mime type the system is reporting by dumping the upload data after your upload

die($this->upload->data());

'file_type'索引将包含一个字符串-将其添加到数组值中,该索引的值与application/config/mimes.php中所需的文件扩展名相匹配

The 'file_type' index will contain a string - add this to the array value with the index that matches the desired file extension in application/config/mimes.php

2-最近一次是我将核心Codeiginter版本从2.x升级到3.x的.我更新了系统目录的内容,但未更新application/config.我没有发现application/config/mimes.php文件稍有不同的事实-新版本返回一个数组,而旧版本将其作为var包含.解决方法是在较新版本的mimes.php中复制

2 - The most recent time I have had this is when I upgraded my core Codeiginter version from 2.x to 3.x. I updated the contents of the system directory, but not application/config. I didn't spot the fact that the application/config/mimes.php file is slightly different - the newer version returns an array whereas the old one included it as a var. The fix was to copy in the newer version of mimes.php

这篇关于Codeigniter:不允许您尝试上传的文件类型.昨天还好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆