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?

Recommended Answers

All 5 Replies

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.

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.

the server is probably doing that because the upload size limit is too small.

I have increased the post max size and the upload max size to 20m and still having the same problem.

do you still have the

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

element in the form. that could be a possibility.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.