PHP 5.2.0
when using mime_content_type("/path/to/my/video.avi")
I get an empty string every time
When I am supposed to get
video/x-msvideo
What is going on?
Thanks
Phil
PHP 5.2.0
when using mime_content_type("/path/to/my/video.avi")
I get an empty string every time
When I am supposed to get
video/x-msvideo
What is going on?
Thanks
Phil
Perhaps the .avi extension isn't defined in the magic.mime file?
Either way, have you tried using the [man]Fileinfo[/man] extension, as the mime_content_type() has been deprecated in favor of this newer extension.
Sorry but I defined AVI in both Apache's magic.mime and PHP's magic.mime as:
AVI
8 string AVI\ video/x-msvideo
And as:
AVI according to http://www.zjlfj.gov.cn/uploadimg/2007416/up1179247864278.php?action=view&file=%2Fusr%2Fshare%2Fmagic.mime
8 string AVI\ video/avi
And yet mime_content_type() still returns an empty string for .avi - not sure if my entries in both magic.mime files were correct; I guessed it
and as far as the PECL extension is concerned, according to the user notes at http://us.php.net/Fileinfo , there must be the defined extension to .avi at /etc/magic.mime - and BTW I'm using Windows, so of course there is no /etc/magic.mime
..not to mention I can't use the Un*x "file -i" option either, same reason..
If you do a phpinfo(), do you see a table called mime_magic ? In it, you should see a directive called "mime_magic.magicfile". Does this point to the path of your magic.mime file?
When I used this function, .avi files were returning "audio/x-wav". I had to add this:
8 string AVI video/x-msvideo
to the top of my magic.mime file (or, at least above the audio/x-wav line). Once I did that, I restarted Apache and the function returned "video/x-msvideo" as expected.
bradgrafelman wrote:If you do a phpinfo(), do you see a table called mime_magic ? In it, you should see a directive called "mime_magic.magicfile". Does this point to the path of your magic.mime file?
No I don't, and it might help to know I'm using WAMP 5.0 for XP so I probably won't
When I used this function, .avi files were returning "audio/x-wav". I had to add this:
8 string AVI video/x-msvideo
to the top of my magic.mime file (or, at least above the audio/x-wav line). Once I did that, I restarted Apache and the function returned "video/x-msvideo" as expected.
Sorry, no love, did exactly as you suggested and no results were generated, still returns empty string for mime_content_type() for avi
How about the phpinfo() bit? Did you check that?
bradgrafelman wrote:How about the phpinfo() bit? Did you check that?
Like I said, there was nothing, no table for magic.mime, no mention of mime_magic, nothing whatsoever using phpinfo()
In your php.ini file, do you see an extension line for php_mime_magic.dll ? Is it commented out?
Wow, not only did that not work but Apache crashed the moment I tried that and loading any PHP page that called mime_content_type() with AVI!!
One more thing, I restarted my machine, everything.. your changes you recommended made no difference still, still get an empty string!
ppowell wrote:Apache crashed the moment I tried that
Tried what? Was the extension line for that dll commented out?
If it was, and uncommenting it crashed Apache, could you paste all of the extension lines from your php.ini file? Also, try setting "display_startup_errors" to "On", "display_errors" to "On", and "error_reporting" to E_ALL. Then, restart Apache (with the extension enabled) and see what happens.
I tried your suggestion of uncommenting the line that points to the dll, only to have Apache completely lock up. I was able to "free the lock" with, believe it or not, a well-placed die() statement (the app didn't die, it just decided to "keep going".. PHP mystifies me)
I tried setting display_startup_errors, display_errors to "On" and error_reporting to E_ALL, restarted Apache, to no avail, still locked up cold until I did the "die()" trick.
However, I still get an empty string with mime_content_type() for AVI
I failed to note that you're using PHP5, as I was testing in PHP4. When I switched the script over to PHP5, I started to notice issues with PHP5's mime_magic support.
Here's what I did. Uncomment the php_mime_magic.dll extension line in your php.ini file, then find this header:
;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;
and add this directly after it:
[Mime Magic]
mime_magic.magicfile = c:/php/magic.mime
mime_magic.debug = Off
Make sure you replace the magicfile path with the correct path for your system.
What's curious is that I see this in my phpinfo output now: mime_magic support | invalid magic file, disabled. Despite its claim, mime_content_type() still works and indeed returned the correct value for an AVI file (using our modified version, with the new AVI stuff at the top).
EDIT: Okay, I found the issue that causes PHP5 to say it's an invalid MIME file, but it should still process it... mine appears to do so. The solution would be to point PHP to use the magic file provided by Apache2 (and add the AVI line to that, if you chose to do this).
Ok here we go, I did exactly as you suggested: here is the line in php.ini:
;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;[Mime Magic]
mime_magic.magicfile = C:/wamp/Apache2/conf/magic
mime_magic.debug = Off
And this points to the magic file within Apache which has this line for AVI:
AVI
8 string AVI video/x-msvideo
..to no avail. Still mime_content_type() returns NULL for AVI!!
Phil
I don't know if it's PHP's fault or what, but it's not following the proper mime syntax/logic. So, go back to using the magic.mime file included with PHP, and fine this line:
0 string RIFF audio/x-wav
It's line #93 for me. Right before that line, add this:
8 string AVI video/x-msvideo
Sorry, Brad, but that didn't work.
FOR AVI AS OF 7/4/2007
8 string AVI video/x-msvideo
0 string RIFF audio/x-wav
Same problem.
I have a better idea. If you have a way for me to send you both php.ini and magic.mime you can see for yourself.
Might help that I am using WAMP 5.0
Phil
You can attach your magic.mime file to a post (might have to be a .txt extension for you to upload it, though) and I can look at it... though if that doesn't work, I'm not sure what to say - it worked on my computer for the AVI's I have.
I attached php.ini, magic (Apache2) and magic.mime (PHP) not being sure what you exactly would need but wouldn't hurt. Thanx!
Consider this function:
if (!function_exists('mime_content_type_fileinfo')) {
/**
* Will use {@link http://us2.php.net/fileinfo FileInfo} functions provided within {@link http://pecl.php.net PECL} bundle to return mime type
*
* @param string $file
* @return string $mime_type
* @see mime_content_type
*/
function &mime_content_type_fileinfo($file) {
global $windowsMagicMimePath, $mimeTypeFilePath;
$mimePath = (($_ENV['windir'] || $_SERVER['windir']) && $windowsMagicMimePath) ? $windowsMagicMimePath : $mimeTypeFilePath;
if (is_class('FileInfo')) {
$finfo =& new FileInfo(FILEINFO_MIME, $mimePath);
if (is_object($finfo)) {
return $finfo->file($file);
} else if (function_exists('finfo_open')) {
return finfo_file(finfo_open(FILEINFO_MIME, $mimePath), $file);
} else {
return mime_content_type($file);
}
} else if (function_exists('finfo_open')) {
return finfo_file(finfo_open(FILEINFO_MIME, $mimePath), $file);
} else {
return mime_content_type($file);
}
}
}
I wrote that in desparation at 2am trying to get anything to work to get AVI files to be recognized.. I wound up finding php_fileinfo.dll in my library, so added it to php.ini and restarted web services..
strangely enough, all PECL-related FileInfo functions and classes do not exist
However, AVI files do!!!
I have absolutely NO explanation for this one! PHP people, you tell me this one! Explain how adding a PECL extension can fix an AVI problem by not existing!
Ref: http://us2.php.net/manual/en/install.pecl.windows.php
Phil