Strange CodeIgniter file upload error

自古美人都是妖i 提交于 2019-12-10 10:31:37

问题


I've set up 'Uploadify' to upload files to my server where I process them with CodeIgniter's file upload library.

However, I think Uploadify changes the mime type of the files, or does something else weird which causes CodeIgniter to give a 'the file type is not allowed' error despite it being allowed.

E.g I've allowed JPEG files but when I upload them using Uploadify, I get that error.

Is there any workaround for this? Basically, I want only image uploads to be allowed, e.g .jpg, .jpeg, .bmp, .png. Do I have to manually check the extension of the files or is there any better option?


回答1:


You're correct, uploadify uses the mime type application/octet-stream for most (all?) the files which it uploads. I think this is actually caused by Flash handling the uploading, but I'm not 100% sure.

In your controller where you handle the upload, drop in a print_r($_FILES) and check out what the mime-type is, then just add it to your application/config/mimes.php file.

So in your mimes.php file you'll probably have something like:

'jpg'   =>  array('image/jpeg', 'image/pjpeg', 'application/octet-stream'),


来源:https://stackoverflow.com/questions/6484289/strange-codeigniter-file-upload-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!