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).

        8 days later

        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

                      Yep after testing I verified, the moment I added the fileinfo DLL (for Windows) into php.ini all AVI files were recognized by PHP's mime_content_type() function.

                      So by adding the AVI line (right before the "RIFF" line) into both Apache and PHP's magic files, adding the extension line to php_fileinfo.dll (or .so if non-Windows) to php.ini, and while you don't get all FileInfo functionality (functions only work in CLI PHP; nothing works in SAPI PHP), you can at least see AVI files.

                      Phil

                        Write a Reply...