473,382 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 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 4659
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: comp.lang.php | last post by:
PHP 4.3.8 with UNIX with option --with-magic_mime echo mime_content_type('/images/myimage.png'); // RETURNS "text/plain" PHP 4.3.11 with UNIX with option --with-magic_mime echo...
50
by: Michael Mair | last post by:
Cheerio, I would appreciate opinions on the following: Given the task to read a _complete_ text file into a string: What is the "best" way to do it? Handling the buffer is not the problem...
1
by: Bill Woodruff | last post by:
As an exercise I wrote a small C# program to download several hundred text files of guitar tab music by parsing the home page of the site and retrieving all the links to the music text files and...
7
by: Rich | last post by:
Is the link rel="stylesheet" supposed to be real plain text, or would some word processor format such as Word/Pad work? This sample stylesheet seems garbled if downloaded and opened with...
6
by: bfowlkes | last post by:
Hello, I am trying to parse two pre-formatted text files and write them to a different files formatted in a different way. The story about this is I was hired along with about 20 other people...
3
by: weichenxi | last post by:
Greetings. I'm not very proficient in asp- just started last month. Sorry if this has already been answered- didn't know what to search for. I'm trying to create multiple text files from a...
0
by: ehcy | last post by:
hi.. can you plz help me... i want to put an "==" in my opened text files but i don't know how.. i will show you the original output and my own program.. ...
5
by: Davo1977 | last post by:
Analysing text files to obtain statistics on their content You are to write a Perl program that analyses text files to obtain statistics on their content. The program should operate as follows: ...
16
by: Wayne | last post by:
I've read that one method of repairing a misbehaving database is to save all database objects as text and then rebuild them from the text files. I've used the following code posted by Lyle...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.