?
Solved

File upload size check failing

Posted on 2003-11-06
5
Medium Priority
?
465 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 500 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

719 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