Telling users file is too large

Reply

Join Date: Mar 2008
Posts: 12
Reputation: camdes is an unknown quantity at this point 
Solved Threads: 0
camdes camdes is offline Offline
Newbie Poster

Telling users file is too large

 
0
  #1
Apr 17th, 2008
I have an HTML form for authorised users to upload photographs and am having problems with file size. I have my test server restricted to 2m filesize upload and am trying to add something to tell my users if they go above this.

I have tried using a hidden field in my form like this:
  1. <input type="hidden" name="MAX_FILE_SIZE" value="2000000">

When I try to upload larger files I do not get an error and on checking, the uploaded file size is 0.

How do I give an error message telling my user to reduce the file size?
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Telling users file is too large

 
0
  #2
Apr 17th, 2008
use:

  1. $tmpFile = $_FILES['file']['tmp_name'];
  2. $size = filesize($tmpFile);
  3. if ($size > 200000) {
  4. echo 'File exceeds size limit';
  5. }

this is just an example you can manipulate this any way you want.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 12
Reputation: camdes is an unknown quantity at this point 
Solved Threads: 0
camdes camdes is offline Offline
Newbie Poster

Re: Telling users file is too large

 
0
  #3
Apr 18th, 2008
Originally Posted by kkeith29 View Post
use:

  1. $tmpFile = $_FILES['file']['tmp_name'];
  2. $size = filesize($tmpFile);
  3. if ($size > 200000) {
  4. echo 'File exceeds size limit';
  5. }

this is just an example you can manipulate this any way you want.
Still having problems!!!!

used the following

  1. $tmpFile = $_FILES['userfile']['tmp_name'];
  2. $size = filesize($tmpFile);
  3. if ($size > 200000) {
  4. echo 'File exceeds size limit';
  5. }
  6.  
  7. $userfile_name=$HTTP_POST_FILES['userfile']['name'];
  8. $userfile_size=$HTTP_POST_FILES['userfile']['size'];
  9. $userfile_type=$HTTP_POST_FILES['userfile']['type'];
  10.  
  11. echo ("upload date: $uploaddate<BR>\n");
  12. echo ("category: $category<BR>\n");
  13. echo ("temp file name: $tmpFile<BR>\n");
  14. echo ("new file name: $userfile_name<BR>\n");
  15. echo ("caption: $caption<BR>\n");

When a small enough file is uploaded I get this:

upload date: 18-4-08, 15:55:03
category: p1
temp file name: C:\wamp\tmp\php1D.tmp
new file name: P1000275.JPG
caption: test caption for small file
filesize: 108024
../gallery/P1000275.JPG uploaded successfully!
Your Photograph was successfully uploaded!

When I try to upload a large file I get:

upload date: 18-4-08, 15:58:35
category: p1
temp file name:
new file name: P1000285.JPG
caption: test caption for large file
filesize: 0
Error: File uploaded has no image

Obviously the file size is being read at the server and with no file being uploaded because of the size it is reading 0.

Can someone help me to read the file size on the client's computer before uploading.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Telling users file is too large

 
0
  #4
Apr 18th, 2008
the server is probably doing that because the upload size limit is too small.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 12
Reputation: camdes is an unknown quantity at this point 
Solved Threads: 0
camdes camdes is offline Offline
Newbie Poster

Re: Telling users file is too large

 
0
  #5
Apr 18th, 2008
I have increased the post max size and the upload max size to 20m and still having the same problem.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Telling users file is too large

 
0
  #6
Apr 18th, 2008
do you still have the

  1. <input type="hidden" name="MAX_FILE_SIZE" value="2000000">

element in the form. that could be a possibility.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC