Solved

File upload size check failing

Posted on 2003-11-06
5
449 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
Comment Utility
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
Comment Utility
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
Comment Utility
<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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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.

772 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

11 Experts available now in Live!

Get 1:1 Help Now