Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

php - Codeigniter : The filetype you are attempting to upload is not allowed. Yesterday it was fine

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.

My config array is:

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

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

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] => 
)

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.

The server is Apache.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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());

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 - 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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...