Solved

File upload size check failing

Posted on 2003-11-06
5
463 Views
Last Modified: 2013-12-13
Hi all,

I'm having a few problems with a file upload script that I'm writing. It seems that my error trapping to check for maximum file size is not working properly.

Here's my form code (stripped down a bit and just the usual basic stuff):

[PHP]

<form name="upload" method="post" action="process_upload.php" enctype="multipart/form-data">
  <input type="file" name="file">
  <input type="submit" name="Submit" value="Submit">
</form>

[/PHP]

And here's the code at the top of  "process_upload.php":



[PHP]<?php

$max_docsize ="2000000";
 
      if(($_FILES['file']['size']) > $max_docsize){

      echo "File is too big";
      exit():
}
?>
[/PHP]

PHP is throwing a wobbly complaining that the MAX_UPLOAD_SIZE has been exceeded and that it was unable to process the file.
…yet if I knock the $max_docsize variable down to something really small such as "100", then try uploading a small 400kb file, the error trapping works.
It just seems that anything over 2mb is not being picked up by the script before PHP tries to process it…

I don't want/need to alter to the php.ini file on the remote server, ... all I'm trying to achieve is that my error message and exit() commeand works before php throws its wobbly.

I'm stumped!!!
GGrrrrrrr  :(
0
Comment
Question by:mattyd2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 5

Expert Comment

by:Karitz
ID: 9693091
Check the limits in your php.ini


you might have it set to 2MB

change it to say 6MB and see what happens
0
 

Author Comment

by:mattyd2
ID: 9693107
I cannot change the limit on the php.ini file as it is determined by the hosting company.

I just want a friendly error message to appear instead of the "MAX_UPLOAD_SIZE has been exceeded" error which is appearing.

Can anyone help??... Please
0
 
LVL 5

Accepted Solution

by:
Karitz earned 125 total points
ID: 9693176
<input type="hidden" name="MAX_FILE_SIZE" value="3000000098">

then include this code before you upload the file to overide what the php.ini limit is. However if the admin has put restrictions on the size of files you can upload you cannot do it.

You code now looks like

<form name="upload" method="post" action="process_upload.php" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="30000">
  <input type="file" name="file">
  <input type="submit" name="Submit" value="Submit">
</form>
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

623 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