2

I am checking if the file is of mp4 format once a user submits the form, this does not work for me:

if(!($_FILES["videoFile"]["type"] == "video/mp4"))
{
   // error handling
}

The file type works for other file types such as png/jpg ect but not for mp4.

echo $_FILES["videoFile"]["type"] = [tmp_name] 
echo $_FILES["videoFile"]["name"] = movie_300.mp4

when I print out the array of files i get:

Array ( [videoFile] => Array ( [name] => movie_300.mp4 [type] => [tmp_name] => [error] => 1 [size] => 0 ))

Why is my file type [tmp_name] when uploading mp4s?

user3753569
  • 1,775
  • 5
  • 14
  • 18
  • 1
    Have you checked the value of $_FILES["videoFile"]["type"]? – Dan Sep 10 '14 at 19:26
  • 2
    can you put the out put of on submit. – sugunan Sep 10 '14 at 19:27
  • Please see: http://stackoverflow.com/a/6755263/258674 – dev-null-dweller Sep 10 '14 at 19:32
  • You could also check your input's name `videoFile` is not the same as `videofile`. Also try a "positive" approach `if($_FILES["videoFile"]["type"] == "video/mp4"){...} else{...}` – Funk Forty Niner Sep 10 '14 at 19:33
  • It's not a case sensitivity issue fred. @guru i printed out the results and the type is [tmp_name] – user3753569 Sep 10 '14 at 19:39
  • @dev-null-dweller can i use "exif_imagetype" for video formats? – user3753569 Sep 10 '14 at 19:43
  • _Why is my file type [tmp_name] when uploading mp4s?_ It's not, it's empty, as is `[type]`, the uploaded file size is also 0. `[error] => 1` Indicates that you have an error uploading the file, try dumping `$_FILES["videoFile"]["error"]` to see what it is. – The Blue Dog Sep 10 '14 at 19:50
  • @TheBlueDog when I print `$_FILES["videoFile"]["error"]` it outputs: 1. Is there a proper way to dump the error data or display the message associated with 1? I am quite new to PHP – user3753569 Sep 10 '14 at 19:55
  • You have an error on file upload. May be server limited by file size. Or write permission issue on server. – sugunan Sep 10 '14 at 19:57
  • 1
    I sure have. I just made a 1second mp4 and it works. Thanks for helping me, most people on this site have no patience for new users. – user3753569 Sep 10 '14 at 20:04

2 Answers2

2

You've exceeded your maximum file upload size, see here.

You can increase this using the following directive at the top of your script:

ini_set('upload_max_filesize', '10M'); // set max size to 10M (or whatever)
The Blue Dog
  • 2,475
  • 3
  • 19
  • 25
0

Here's a neat little function.

http://subinsb.com/php-find-file-mime-type

I'd be careful with your validation because I'm pretty sure mimes can be spoofed fairly easily. Maybe someone with more security experience can weigh in on that subject. I'd at least perform a few other checks.

Cheers!

DeFeNdog
  • 1,156
  • 1
  • 12
  • 25