Solved

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

Posted on 2012-04-12
5
373 Views
Last Modified: 2012-04-12
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
0
Comment
Question by:peps03
  • 2
  • 2
5 Comments
 
LVL 21

Accepted Solution

by:
Kim Walker earned 500 total points
Comment Utility
Depending on the browser, if your file is bigger than about 10K it will not send a file at all. So the file type would be null which is != "application/pdf".
0
 

Author Comment

by:peps03
Comment Utility
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..
0
 
LVL 21

Expert Comment

by:Kim Walker
Comment Utility
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.
0
 

Author Closing Comment

by:peps03
Comment Utility
Ok, thanks again!
0
 
LVL 20

Expert Comment

by:Mark Brady
Comment Utility
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.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
Showing your events from Google Calendar in Google Maps Why? I travel all week and I thought it would be ideal if staff in office knew where I was based on my calendar. (OK real reason: my son wanted to see where I would be working, and I thoug…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now