Form Tools
Show error if file upload exceeds limit - Printable Version

+- Form Tools (https://forums.formtools.org)
+-- Forum: Form Tools (https://forums.formtools.org/forumdisplay.php?fid=1)
+--- Forum: Feature Suggestions (https://forums.formtools.org/forumdisplay.php?fid=7)
+--- Thread: Show error if file upload exceeds limit (/showthread.php?tid=1995)



Show error if file upload exceeds limit - JediCharles - Apr 20th, 2012

When files being uploaded exceed the limit there needs to be an error message stating that the file is too large. Currently if the file is too large a 500 Internal Server Error is displayed and the message get's sent with no files.


RE: Show error if file upload exceeds limit - bills - Aug 16th, 2012

(Apr 20th, 2012, 2:29 PM)JediCharles Wrote: When files being uploaded exceed the limit there needs to be an error message stating that the file is too large. Currently if the file is too large a 500 Internal Server Error is displayed and the message get's sent with no files.

I solved that issue using javascript placed at the beginning of the process.php file located in the formtools installation folder.

$max_filesize = 524288;
// Maximum filesize in BYTES (currently 0.5MB).

$upload_path = '../formtools/upload/'; // change to your upload path

$filename = $_FILES['userfile']['name'];
// Get the name of the file (including file extension).

$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
// Get the extension from the filename.

// Now check the filesize, if it is too large then DIE and inform the user.
if(filesize($_FILES['userfile']['name']) > $max_filesize)
die('The file you attempted to upload is too large.');

Then add to 'die'.
<a href="#" onclick="history.go(-1);return false;">BACK</a>