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?

Ozair Kafray
  • 13,351
  • 8
  • 59
  • 84
Pradip
  • 1,317
  • 4
  • 21
  • 36
  • By extension...or using the http://www.php.net/manual/en/function.finfo-file.php functions on the $_FILES['file']['tmp_name'] – Catalin Jun 14 '11 at 06: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. – Salman A Jun 14 '11 at 06:51

1 Answers1

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

Bob_Gneu
  • 1,591
  • 1
  • 18
  • 30
  • Using that function it should come back as 'video/mp4', but it is only available once it has been uploaded. – Bob_Gneu Jun 14 '11 at 06:40
  • Oh, and if you aren't able to get access to the library on your install (or its not available) this may be useful: http://stackoverflow.com/questions/652002/detecting-mime-type-in-php – Bob_Gneu Jun 14 '11 at 06:44
  • "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 ;) – Catalin Jun 14 '11 at 07:17
  • Yes, i was only clarifying for him. =) Thank you! – Bob_Gneu Jun 14 '11 at 07:26