|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-06-25 17:00 UTC] spam2 at rhsoft dot net
Description:
------------
i have at least one GIF image with 2.3 MB which is detected as application/octet-stream while '/usr/bin/file -b --mime-type' on the same machine correctly results in image/gif
sadly i don't see here any option to attach the image :-(
that makes it hard to implement relieable checks if the
extension of uploads matchs the expected mime-type
[harry@srv-rhsoft:~/Desktop]$ php mime.php
/usr/bin/file -b --mime-type
image/gif
finfo_file(filename, FILEINFO_MIME_TYPE)
application/octet-stream
Test script:
---------------
#!/usr/bin/php
<?php
echo '/usr/bin/file -b --mime-type' . "\n";
passthru('/usr/bin/file -b --mime-type ' . escapeshellarg(__DIR__ . '/1.gif'));
echo "\n";
echo 'finfo_file(filename, FILEINFO_MIME_TYPE)' . "\n";
$finfo_handle = finfo_open();
echo finfo_file($finfo_handle, __DIR__ . '/1.gif', FILEINFO_MIME_TYPE) . "\n";
finfo_close($finfo_handle);
?>
Expected result:
----------------
image/gif as result
Actual result:
--------------
application/octet-stream as result
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 01:00:02 2025 UTC |
Thanks for making the file available, and sorry for the bad pointer to picpaste.com. Anyhow, a quick check: cmb@debian64:~$ file -b --mime-type 67516.gif application/octet-stream cmb@debian64:~$ dpkg -s file Package: file Status: install ok installed Priority: standard Section: utils Installed-Size: 119 Maintainer: Christoph Biedl <debian.axhn@manchmal.in-ulm.de> Architecture: amd64 Multi-Arch: foreign Version: 1:5.22+15-2 Depends: libc6 (>= 2.4), libmagic1 (= 1:5.22+15-2), zlib1g (>= 1:1.1.4) Description: Determines file type using "magic" numbers File tests each argument in an attempt to classify it. There are three sets of tests, performed in this order: filesystem tests, magic number tests, and language tests. The first test that succeeds causes the file type to be printed. Homepage: http://www.darwinsys.com/file/ Which version of file/libmagic do you use?