Uploader.php function _file_mime_type fails in CI 2.1 |
[eluser]ksorbo[/eluser]
There has been quite a bit of discussion in the code forum about problems uploading files (invalid file type). I have read all of them and nothing they did solved my problems. I think I have found a problem (on my system, at least). I believe the problem lies with the use of the deprecated mime_content_type php function. From upload.php CI version 2.1 lines 1019 - 1068 Code: protected function _file_mime_type($file) I am running php 5.2.17 so the first IF (line 1022) fails. mime_content_type exists in 5.2.17 so the second if (line 1042) executes. $this->file_type is set using the mime_content_type function. My server passes a random file name for the 'tmp_name' with no file extension. I am uploading docx files and my browser passes the correct mime type. However, the mime_content_type function returns plain text mime type. This causes the entire upload function to fail. <b>My solution: revert to upload.php from 2.0.1.</b> I don't know what the best way would be to detect mime type. The danger of using the browser's data is that it could be hacked allowing the user to upload potentially dangerous files. Obviously this problem goes away if you are using 5.3+. Unfortunately, I had a hard enough time getting my host to move from 4.+ to 5.+ so I am not holding my breath.
[eluser]CroNiX[/eluser]
I know there has been a lot of updates on this in the Github repo, so that version is probably working better.
[eluser]ksorbo[/eluser]
I just took a look at the git source and the function _file_mime_type seems to use the same logic which is tripping me up. Perhaps the authors are using a version of PHP which never encounters the second if statement and thus have never seen this problem.
[eluser]Djaka PM[/eluser]
Hi my name is Djaka, Currently I am facing an issue on the Upload library, I am using - CI 2.1.0 - PHP Version 5.3.6-13ubuntu3.6 The issue actually not in the CI framework, but in a PHP function called "Fileinfo" The Fileinfo function is called in CI`s _file_mime_type function inside Upload.php file , so my case is: I am try to upload csv file, I already make sure that the file extension is correct and the allowed mime types are "csv|txt". CI is already guess the file extension correctly("text/csv"), but by the time the CI called the "Fileinfo" function it return "text/plain", which is in my opinion is not correct. Is there any workaround? Some says that the "Fileinfo" is not quite reliable. http://stackoverflow.com/questions/46071...e-from-php For now I set the allowed mime types to wildcard, which will cause security issue. Thanks.
[eluser]Narf[/eluser]
The Upload library has been updated, try it: https://raw.github.com/EllisLab/CodeIgni...Upload.php
[eluser]bluepicaso[/eluser]
[quote author="Djaka PM" date="1331116408"]Thanks Narf. I will try the new Upload.php[/quote] Did you get this to work? New library did not help me though
[eluser]Djaka PM[/eluser]
Yup the new library still got it wrong. I think this issue only happens on *nix system. Because when I did try my application on Windows it working correctly.
[eluser]bluepicaso[/eluser]
[quote author="Djaka PM" date="1332313710"]Yup the new library still got it wrong. I think this issue only happens on *nix system. Because when I did try my application on Windows it working correctly. [/quote] hmmm ok i used valum's upload instead
[eluser]Djaka PM[/eluser]
who is valum? can you share the code? because i do still dont know the workaround |
Welcome Guest, Not a member yet? Register Sign In |