| | |
Telling users file is too large
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2008
Posts: 12
Reputation:
Solved Threads: 0
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:
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?
I have tried using a hidden field in my form like this:
PHP Syntax (Toggle Plain Text)
<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?
use:
this is just an example you can manipulate this any way you want.
PHP Syntax (Toggle Plain Text)
$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.
•
•
Join Date: Mar 2008
Posts: 12
Reputation:
Solved Threads: 0
•
•
•
•
use:
PHP Syntax (Toggle Plain Text)
$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.
used the following
PHP Syntax (Toggle Plain Text)
$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.
do you still have the
element in the form. that could be a possibility.
PHP Syntax (Toggle Plain Text)
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
element in the form. that could be a possibility.
![]() |
Similar Threads
- Programming FAQ - Updated 1/March/2005 (Computer Science)
- memory management in wndows 2000 (Windows NT / 2000 / XP)
- Using two vectors? (C++)
- Aurora/DrPmon/shopathomeselect..Please Help Me.. (Viruses, Spyware and other Nasties)
Other Threads in the PHP Forum
- Previous Thread: PEAR email
- Next Thread: mysql_fetch_array warning urgent plz
| Thread Tools | Search this Thread |
.htaccess ajax apache api array beginner binary broken buttons cakephp checkbox class cms code cron curl database date directory display download dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail mediawiki menu mlm mod_rewrite multiple mysql number oop paypal pdf php phpincludeissue phpmyadmin problem query radio random recursion regex remote script search server sessions sms soap source sp space speed sql subdomain syntax system table tag tutorial update upload url validation validator variable vbulletin video web websphere white xml youtube






