Donations accepted

Hosted on verot.net

class upload detects the image as plain text

See all posts Reply

class upload detects the image as plain text new!
by Carlos, 2 years ago
Hello,
I have a problem with the class.
When upload a image, the class detected the image as plain/text.
I don't know what happened.

The log is:
system information
- class version : 0.29
- operating system : Linux
- PHP version : 5.3.6-13ubuntu3.6
- GD version : 2.0
- supported image types : png jpg gif bmp
- open_basedir : no restriction
- language : en_GB
source is a local file /tmp/phptU06cW
- local file name OK
determining MIME type
- Checking MIME type with Fileinfo PECL extension
MAGIC path defaults to /usr/share/file/magic
MIME type detected as application/octet-stream; charset=binary by Fileinfo PECL extension
- MIME validated as application/octet-stream
- Flash may be rewriting MIME as application/octet-stream
- Try to guess MIME type from file extension (): doesn't look like anything known
source variables
- You can use all these before calling process()
file_src_name : phptU06cW
file_src_name_body : phptU06cW
file_src_name_ext :
file_src_pathname : /tmp/phptU06cW
file_src_mime : application/octet-stream
file_src_size : 452061 (max= 2097152)
file_src_error : 0
process file to /var/www/Phaloo/application/../temp/
- file size OK
- script phptU06cW renamed as phptU06cW.txt!
- file mime OK : text/plain
- new file name ext : jpeg
- new file name body : 193585_original
- new file name ext : jpeg
- file name safe format
- destination variables
file_dst_path : /var/www/Phaloo/application/../temp/
file_dst_name_body : 193585_original
file_dst_name_ext : jpeg
- no image operation, keep extension
- checking for auto_rename
- destination file details
file_dst_name : 193585_original.jpeg
file_dst_pathname : /var/www/Phaloo/application/../temp/193585_original.jpeg
- 193585_original.jpeg doesn't exist already
- no image processing wanted
- process OK
Reply
Re: class upload detects the image as plain text new!
by colin, 2 years ago
Your system doesn't find the correct MIME type. Maybe Fileinfo PECL is wrongly set up.

Try to deactivate some methods in the class code, to see which one work:
// these are the different MIME detection methods. if one of these method doesn't work on your
// system, you can deactivate it here; just set it to false
$this->mime_fileinfo            = true;     // MIME detection with Fileinfo PECL extension
$this->mime_file                = true;     // MIME detection with UNIX file() command
$this->mime_magic               = true;     // MIME detection with mime_magic (mime_content_type())
$this->mime_getimagesize        = true;     // MIME detection with getimagesize()

Start by setting mime_fileinfo to false.Reply
Re: class upload detects the image as plain text new!
by Hristo Erinin, 1 year, 12 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
Re: class upload detects the image as plain text new!
by Mario, 1 year, 11 months ago
Thank you Hristo,
I have had same problem with my Ubuntu 11.4 Natty with PHP 5.3.5.
I have resolved it by adding ".mgc" extension in class.upload.php /usr/share/file/magic.mgc.. as you suggested
Now works great, thank you for saving me a few hours of trouble!
MarioReply