Solved

File upload size check failing

Posted on 2003-11-06
5
459 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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What does this formatting equate to? 7 18
simple html dom php accessing table/cell  values 4 23
Ajax and PHP 4 31
Ajax and PHP 9 31
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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…
The viewer will learn how to dynamically set the form action using jQuery.

830 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