![]() |
File Upload Class - MIME type detection error - 2.1.0 - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: File Upload Class - MIME type detection error - 2.1.0 (/showthread.php?tid=46852) Pages:
1
2
|
File Upload Class - MIME type detection error - 2.1.0 - El Forum - 11-17-2011 [eluser]Unknown[/eluser] There is a bug with the File Upload Class in the _file_mime_type function. 1. Uploading any image with the following config would generate the error 'The filetype you are attempting to upload is not allowed.': Code: $config = array( 2. Changing 'allowed_types' to '*' allows the file to be uploaded, however the upload data array ( $this->upload->data() ) contains an error: Code: [file_type] => cannot open `' (no such file or directory) 3. Looking at system/libraries/Upload.php , Line 1058 tries to use an array value that does not exist. Code: @exec('file --brief --mime-type ' . escapeshellarg($file['tmp_path']), $output, $return_code); Changed to: Code: @exec('file --brief --mime-type ' . escapeshellarg($file['tmp_name']), $output, $return_code); This seems to detect the proper MIME type. ---- System Info: PHP 5.2.11 (MAMP 1.0) - Mac OS X 10.6.8 File Upload Class - MIME type detection error - 2.1.0 - El Forum - 04-16-2012 [eluser]Unknown[/eluser] isn't it too risky?? what if someone upload not image file... if someone try too hacking with this hole... i don't know what to do about this... but while I chose the first answer where the file type change to *... thx for sharing... File Upload Class - MIME type detection error - 2.1.0 - El Forum - 04-19-2012 [eluser]CocoMansur[/eluser] [quote author="victorche" date="1322829005"]Anyway... The guy, who made some changes in the upload class, gave me a fix for my problem. It appears on Windows machines, when sometimes mime_content_type returns false. And the fix is like this... On line 1058 (/system/libraries/Upload.php): Code: $this->file_type = @mime_content_type($file['tmp_name']); Code: $this->file_type = @mime_content_type($file['tmp_name']); Edit: This is the fix, with the pull request on GitHub from my friend: https://github.com/EllisLab/CodeIgniter/pull/733[/quote] Thanks for this fix, this worked for me, i applied the first fix but i was still having problem when uploading a file that is allowed on my config. I applied the first fix with this fix and now it works. Thanks. hopefully they will fix this issue on the next version. File Upload Class - MIME type detection error - 2.1.0 - El Forum - 05-16-2012 [eluser]StickGrinder[/eluser] Just in case someone else has this error and above solutions don't work: I'm running CI 2.1 (vanilla) on PHP 5.3.10 - (mod_php, Ubuntu server) and the error persists. Figured out that in system/libraries/Upload.php, from line 597 the following code Code: $ext = strtolower(ltrim($this->file_ext, '.')); invariabily fails, since for what I think is a bug in PHP, $ext value before the if statement is correct, while after the if statement (and during it, it seems), it changes. To check this out try this: Code: $ext = strtolower(ltrim($this->file_ext, '.')); Changing the variable name to $fext across all class did the trick for me: the value remains untouched. EDIT: I lied! It fails equally. The ONLY viable solution I found is to use a constant instead. AWFUL solution follows! Code: define('ULFEXT', strtolower(ltrim($this->file_ext, '.'))); Thanks PHP. And if someone is thinking about testing out some other framework, my advice is to frog-leap to another language too. ![]() File Upload Class - MIME type detection error - 2.1.0 - El Forum - 05-17-2012 [eluser]Binod Kumar Luitel[/eluser] Update to stable version for this issue's fix: https://github.com/EllisLab/CodeIgniter/tree/2.1-stable File Upload Class - MIME type detection error - 2.1.0 - El Forum - 06-27-2012 [eluser]Unknown[/eluser] This is still a problem even with the latest update to Upload.php. I'm using the library to upload document files, no images are allowed. Code: $config['allowed_types'] = 'doc|docx|txt|rtf|pdf'; I can upload all but the docx file types. When I dump the contents of Code: $this->upload->data() When uploading docx files I get a wrong file type error. File Upload Class - MIME type detection error - 2.1.0 - El Forum - 07-06-2012 [eluser]Unknown[/eluser] I as well am still encountering these problems with the latest CI. In fact, I tried doing Code: $config['allowable-types'] = '*'; Edit: I stand corrected, my problems are solved. I am supposed to use Code: $config['allowed_types'] File Upload Class - MIME type detection error - 2.1.0 - El Forum - 07-17-2012 [eluser]Unknown[/eluser] Had the same problem with not allowing jpgs to be uploaded. I upgraded to 2.1.2 by just overwriting the system folder and it is working correctly now for me. File Upload Class - MIME type detection error - 2.1.0 - El Forum - 07-22-2012 [eluser]kanhai[/eluser] I have tried this with version 2.1.2. It works for jpg files but for some reason it does not work for csv file. File Upload Class - MIME type detection error - 2.1.0 - El Forum - 07-22-2012 [eluser]InsiteFX[/eluser] Instead of trying to fix all this by changing the class why not just submit an issue on it to get it fixed the right way? CodeIgniter Bug Issues |