Link to home
Start Free TrialLog in
Avatar of peps03
peps03

asked on

Uploading file: MAX_FILE_SIZE gives $_FILES["file"]["type"] != "application/pdf" error

Hi,

My file upload script worked correctly until i added:
<input type='hidden' name='MAX_FILE_SIZE' value='10000'>

Now when uploading a pdf file, bigger or smaller than 10000 i get the error i set for a file not being: $_FILES["file"]["type"] != "application/pdf".

When i remove the MAX_FILE_SIZE the error does not appear, and uploading works well again.
What's going on here?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Kim Walker
Kim Walker
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of peps03
peps03

ASKER

Ah, i see. great!
Changing the order of the error messaging worked.
Now i first get the error the file is to big.

Thanks!
May i be so cheeky to ask you 1 more thing before accepting your answer?

Is there a way to check if a pdf is really a pdf? Changing a image's extension (.jpg) to pfd still uploads..
I'm afraid I don't the answer to that. You'd probably need to read the file header and check for a particular match. But I don't know what you'd need to look for.
Avatar of peps03

ASKER

Ok, thanks again!
Avatar of Mark Brady
You can check the file type by using php's inbuilt "$_FILES['file']['type']" on your receiving form/script. Usually the users browser will send the file type information as well so insteadd of checking only for the file extension (which is not a guarantee of file type) you should run another check on the actual type. To get the type you would use:

$file_type = $_FILES['file']['type']; // Now the variable $file_type should contain the in formation you want. Echo the result to see the format it provides then write your checking code to suit.