471,319 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

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

[PHP]
echo mime_content_type('/var/www/html/video/small.mov'); //
1.5mb Quicktime video returns "video/quicktime"
echo mime_content_type('/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_filesize on /etc/php.ini and restarted
HTTPD, however, this did not fix the mime_content_type() 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

Sep 1 '05 #1
10 4490
The large movie file might contain preview info. Try adding this line
to magic.mine:

4 string pnot video/quicktime

Sep 1 '05 #2
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 LimitRequestBody), 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

Sep 1 '05 #3
comp.lang.php (ph**************@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 LimitRequestBody), 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.
Sep 1 '05 #4
Hmmm...do a "echo fread($f, 4);" on the large file and see what you
get. That's what mime_content_type() 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.

Sep 2 '05 #5
Ok, upon running this line for each file it gets in the directory:

[PHP]
while (($fyl = @readdir($dirID)) !== false) {
echo "$locationPath/$fyl: "; echo
bin2hex(@fread(fopen("$locationPath/$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

Sep 13 '05 #6
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

Sep 13 '05 #7
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.

Sep 13 '05 #8
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
"application/octet-stream video/quicktime" for a 10mb Quicktime movie
file

My homegrown mime_content_type() 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_type() 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

Sep 14 '05 #9
A quick search on Google for the string "ftyp" yielded the following
URL:

http://developer.apple.com/documenta...REF/-ftyp-.htm

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.

Sep 14 '05 #10
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

Sep 15 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by comp.lang.php | last post: by
50 posts views Thread by Michael Mair | last post: by
7 posts views Thread by Rich | last post: by
6 posts views Thread by bfowlkes | last post: by
reply views Thread by ehcy | last post: by
5 posts views Thread by Davo1977 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.