Reply to Re: class upload detects the image as plain text

Re: class upload detects the image as plain text new!
by Hristo Erinin, 11 years, 11 months ago
First, thanks for writing and supporting this software, it's extremely useful!

I suspect I've encountered a simillar problem, spent an hour trying to solve it, so here is a short description how I solved it.
My system is Debian 6 (squeeze) updated with the latest packages. Your class was working without any issues with lenny (PHP 5.2) but stopped working with Debian squeeze (PHP 5.3). The main difference, I believe, lies in the fact that Fileinfo is included in PHP 5.3 and is no longer an external library.

The problem is that, by default, your code explicitly sets the MAGIC path. When the path to the libmagic files is set to /usr/share/file/magic, the finfo_file function returns "application/octet-stream" as the mime type (files uploaded through a Uploadify flash applet). On all systems I've checked this path actually is an empty directory. Now, according to the man page libmagic automatically adds a ".mgc" extension when necessary. For some reason, on my systems at least, this doesn't happen, and fileinfo is not working and not returning the actual mime type.

How to solve this problem? I've managed solving it in several different ways. If you explicitly set the path to /usr/share/file/magic.mgc (the compiled magic rules), then the finfo_file works properly and returns image/jpeg. I've done this by setting the MAGIC environment variable (eg. putent('MAGIC=/usr/share/file/magic.mgc');) before calling Process().
I've also noticed, that if I actually force your class to use the finfo class (class.upload.php:2626), instead of the finfo_open and finfo_file functions, it works properly, possibly because you don't set explicitly the MAGIC file path.

This comment http://www.php.net/manual/en/function.finfo-file.php#104396 , appears to be only partially correct.

BTW: I tried testing it with setting $handle->mime_fileinfo='' before the process(), but this didn't work as well - the MAGIC path still was set to the default one. I'm not 100% sure there is a bug, as I was in a hurry and didn't try to confirm this problem.

Hope this helps.

--
HristoReply

Your reply

Name *
Email 
Title *
Text *
CAPTCHA image
Enter the code displayed on the image:
Click on the image to generate another one if it is hard to read it. The case is important