0

I am developing application in PHP which takes video file. I am giving serverside validation ($_FILES['file']['type']) that receive only .MP4 files.

If i upload any MP4 file from Firefox browser then file type is 'application/octet-stream' and if i upload same file from Google Chrome then file type is 'video/mp4'.

If i upload any FLV file from Firefox then file type is also 'application/octet-stream' then how can i identify the file type of that video?

2
  • By extension...or using the php.net/manual/en/function.finfo-file.php functions on the $_FILES['file']['tmp_name'] Commented Jun 14, 2011 at 6:39
  • 1
    Never ever trust the type sent by the browser. It is fairly easy to spoof the mime type of an exe file as something else. Commented Jun 14, 2011 at 6:51

1 Answer 1

3

Have you tried using the file info library? finfo_file()

http://www.php.net/manual/en/function.finfo-file.php

it has a sister function mime_content_type()

http://www.php.net/manual/en/function.mime-content-type.php

Sign up to request clarification or add additional context in comments.

4 Comments

Using that function it should come back as 'video/mp4', but it is only available once it has been uploaded.
Oh, and if you aren't able to get access to the library on your install (or its not available) this may be useful: stackoverflow.com/questions/652002/detecting-mime-type-in-php
"but it is only available once it has been uploaded" ...once you have access to $_FILES var, the file is already on the server in a temporary location ;)
Yes, i was only clarifying for him. =) Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.