Solved

File upload size check failing

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Permalink issue in Wordpress archive 1 32
File submission to SQL Server 1 37
phpmyadmin 3 32
php string masking 4 27
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.

930 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

15 Experts available now in Live!

Get 1:1 Help Now