User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 403,212 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,743 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 375 | Replies: 5
Reply
Join Date: Mar 2008
Posts: 12
Reputation: camdes is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
camdes camdes is offline Offline
Newbie Poster

Telling users file is too large

  #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:
<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?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 553
Reputation: kkeith29 is on a distinguished road 
Rep Power: 3
Solved Threads: 55
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Posting Pro

Re: Telling users file is too large

  #2  
Apr 17th, 2008
use:

$tmpFile = $_FILES['file']['tmp_name'];
$size = filesize($tmpFile);
if ($size > 200000) {
  echo 'File exceeds size limit';
}

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

Re: Telling users file is too large

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

$tmpFile = $_FILES['file']['tmp_name'];
$size = filesize($tmpFile);
if ($size > 200000) {
  echo 'File exceeds size limit';
}

this is just an example you can manipulate this any way you want.


Still having problems!!!!

used the following

$tmpFile = $_FILES['userfile']['tmp_name'];
$size = filesize($tmpFile);
if ($size > 200000) {
  echo 'File exceeds size limit';
}

$userfile_name=$HTTP_POST_FILES['userfile']['name'];
$userfile_size=$HTTP_POST_FILES['userfile']['size'];
$userfile_type=$HTTP_POST_FILES['userfile']['type'];

echo ("upload date: $uploaddate<BR>\n");
echo ("category: $category<BR>\n");
echo ("temp file name: $tmpFile<BR>\n");
echo ("new file name: $userfile_name<BR>\n");
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  
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 553
Reputation: kkeith29 is on a distinguished road 
Rep Power: 3
Solved Threads: 55
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Posting Pro

Re: Telling users file is too large

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

Re: Telling users file is too large

  #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  
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 553
Reputation: kkeith29 is on a distinguished road 
Rep Power: 3
Solved Threads: 55
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Posting Pro

Re: Telling users file is too large

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

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

element in the form. that could be a possibility.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 4:47 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC