mime_content_type() returns "text/plain" for large Quicktime files - HELP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • comp.lang.php

    mime_content_type() returns "text/plain" for large Quicktime files - HELP

    [PHP]
    echo mime_content_ty pe('/var/www/html/video/small.mov'); //
    1.5mb Quicktime video returns "video/quicktime"
    echo mime_content_ty pe('/var/www/html/video/huge.mov'); //
    10.5mb Quicktime video returns "text/plain"
    [/PHP]

    Environment:

    PHP 5.0.4 - Windows XP --enable-mime-magic
    PHP 4.3.11 - Fedora Core 4 --enable-mime-magic

    In both cases, "--enable-mime_magic" was allowed with PHP
    installations. In both cases, if the Quicktime video is small, the
    MIME type returned is right; if the Quicktime video is large, the MIME
    type returned is wrong.

    We managed to change upload_max_file size on /etc/php.ini and restarted
    HTTPD, however, this did not fix the mime_content_ty pe() problem.

    We even changed the mime_magic.path variable to point to HTTPD
    (Apache)'s "magic" file instead of PHP's "magic.mime " file, which fixed
    an earlier problem with PNG images, but not with large MOV files.

    Any suggestions?

    Thanx
    Phil

  • Chung Leong

    #2
    Re: mime_content_ty pe() returns "text/plain" for large Quicktime files - HELP

    The large movie file might contain preview info. Try adding this line
    to magic.mine:

    4 string pnot video/quicktime

    Comment

    • comp.lang.php

      #3
      Re: mime_content_ty pe() returns "text/plain" for large Quicktime files - HELP

      We implemented that line into the magic file, however, the problem not
      only persists, we found out that nearly any file over 8.3mb winds up
      with a "text/plain" MIME type.

      I'm suspecting something within Apache is resetting the max file size
      (I think LimitRequestBod y), however, we're using Apache 2.0.53 and
      Apache 2.0.54 and that variable is no found anywhere, furthermore,
      adding that line to httpd.conf makes no difference.

      Phil

      Comment

      • Malcolm Dew-Jones

        #4
        Re: mime_content_ty pe() returns "text/plain" for large Quicktime files - HELP

        comp.lang.php (phillip.s.powe ll@gmail.com) wrote:
        : We implemented that line into the magic file, however, the problem not
        : only persists, we found out that nearly any file over 8.3mb winds up
        : with a "text/plain" MIME type.

        : I'm suspecting something within Apache is resetting the max file size
        : (I think LimitRequestBod y), however, we're using Apache 2.0.53 and
        : Apache 2.0.54 and that variable is no found anywhere, furthermore,
        : adding that line to httpd.conf makes no difference.

        I don't see why the apache max file size should make any difference.

        However the data structures in the header of the quick time file may have
        to change based on the size of the file, (e.g. perhaps a size field takes
        more bytes, thus upsetting the normal offsets in the header) and so the
        header area of the file may look different for large files.

        I can't give the details, never having had to use them, but I would
        examine the bytes at the start of a number of large quick time files and
        compare them to the bytes in smaller quick time files, and compare all
        that to the data in the mime magic configuration.

        I suspect that you will find the large file does not match the mime magic
        config.

        However, you will probably find a commonality of the large files, such as
        the signature being in a slightly different place, and then you can put
        that into the mime magic config file, after which the correct mime info
        will be returned.

        $0.10

        --

        This programmer available for rent.

        Comment

        • Chung Leong

          #5
          Re: mime_content_ty pe() returns "text/plain" for large Quicktime files - HELP

          Hmmm...do a "echo fread($f, 4);" on the large file and see what you
          get. That's what mime_content_ty pe() does. It reads the first four
          bytes of a file to determine what it is. QuickTime files do not have
          bona fide file headers. They are a series of "atoms" of various type.
          Usually, either a "moov" (meta data) or "mdat" (movie data) comes at
          the beginning of a file. But that's not a requirement. For some reason
          some other atoms are situated at the beginning of your files.

          Comment

          • comp.lang.php

            #6
            Re: mime_content_ty pe() returns "text/plain" for large Quicktime files - HELP

            Ok, upon running this line for each file it gets in the directory:

            [PHP]
            while (($fyl = @readdir($dirID )) !== false) {
            echo "$locationP ath/$fyl: "; echo
            bin2hex(@fread( fopen("$locatio nPath/$fyl", 'rb'), 4)); echo "<P>";

            }
            [/PHP]

            Here were some of the results:

            /var/www/html/tools/app/video/blah/..:

            /var/www/html/tools/app/video/blah/str.mov.html: 3c68746d

            /var/www/html/tools/app/video/blah/movie.mov: 00000020

            /var/www/html/tools/app/video/blah/.:

            /var/www/html/tools/app/video/blah/teaser_lo.mov: 00001193
            MOV file "teaser_lo. mov" is only 3mb in size whereas "movie.mov" is
            over 10mb in size. Sorry I cannot go any further but the concepts of
            bin2hex() and unpack() are lost to 100%-web people like me. I don't
            know how to translate that any further.

            Phil

            Comment

            • comp.lang.php

              #7
              Re: mime_content_ty pe() returns &quot;text/plain&quot; for large Quicktime files - HELP

              I tried the same test with a .wmv and a Real movie file, and the
              results were exactly the same as they were with Quicktime: Anything
              over 8mb or so would produce "text/plain", anything under 8mb produced
              the correct MIME type each time.

              Phil

              Comment

              • Chung Leong

                #8
                Re: mime_content_ty pe() returns &quot;text/plain&quot; for large Quicktime files - HELP

                Sorry, I mistakenly think that the signature would appear at the very
                begining of the file. There are actually some other information prior
                to it. Instead of 4 bytes, print out 16 bytes instead. It'd be helpful
                if you can make the files available online.

                Comment

                • comp.lang.php

                  #9
                  Re: mime_content_ty pe() returns &quot;text/plain&quot; for large Quicktime files - HELP

                  It would be helpful, unfortunately it would also be illegal. These are
                  privatized government scripts and I cannot release them, sorry :(

                  What I can tell you then is this:

                  Using the "file -bi" utility in UNIX, I am having some wildly different
                  results:

                  Red Hat Linux Enterprise Level 3
                  PHP 4.3.2
                  NOT --enable-magic_mime

                  "file -bi /var/www/html/tools/app/video/blah/tiny.mov" yields
                  "video/quicktime" for a 3mb Quicktime movie file

                  "file -bi /var/www/html/tools/app/video/blah/huge.mov" yields
                  "applicatio n/octet-stream video/quicktime" for a 10mb Quicktime movie
                  file

                  My homegrown mime_content_ty pe() function takes over and handles all
                  files large and small with no problem
                  ------------------------------------------------------------------------------------------------------------------

                  Fedora Core 4
                  PHP 5.0.4
                  --enable-magic_mime

                  "file -bi /var/www/html/tools/app/video/blah/tiny.mov" yields "FFF6
                  0xFFF0 audio/X-HX-AAC-ADTS" for a 3mb Quicktime movie file

                  "file -bi /var/www/html/tools/app/video/blah/huge.mov" yields "FFF6
                  0xFFF0 audio/X-HX-AAC-ADTS" for a 10mb Quicktime movie file

                  PHP's mime_content_ty pe() function takes over and files less than 10mb
                  get the correct MIME type whereas files larger than 10mb get the wrong
                  MIME type (text/plain)
                  -----------------------------------------------------------------------------------------------------------------

                  This is too inconsistent to be able to draw any worthwhile conclusion..

                  However, taking your suggest and expanding to 16 bytes, I got it!!

                  ftypqt

                  All files < 10mb return "moov", whereas files >= 10mb return "ftypqt"
                  instead. So now I know what to add into the magic file!

                  Phil

                  Comment

                  • Chung Leong

                    #10
                    Re: mime_content_ty pe() returns &quot;text/plain&quot; for large Quicktime files - HELP

                    A quick search on Google for the string "ftyp" yielded the following
                    URL:



                    Apparently there's a image stored inside the movie. Box cover? Poster?
                    Preview image? The Atom ID link gives you a list of atom ids.
                    Unfortunately, it's quite long. Don't think you can incorporate the
                    entire list into your magic file.

                    Comment

                    • comp.lang.php

                      #11
                      Re: mime_content_ty pe() returns &quot;text/plain&quot; for large Quicktime files - HELP

                      Well I was able to get it to work with "ftypqt" (for Quicktime I
                      assume), so thanx a lot for your help, it works now!!

                      Phil

                      Comment

                      Working...