Display an upload error attemting uploading a 2 large file?
Moderator: General Moderators
Display an upload error attemting uploading a 2 large file?
I have a php script that uploads an image to my mySQL DB. My MAX_FILE_SIZE setting has been set to 1000000. Now, how do I get my php page to display a nice message to my visitor when he has exceeded the allowable file size.
I know its not possible with JavaScript, due to security reasons, and I'm also not prepared to use ActiveX.
Any ideas?
I know its not possible with JavaScript, due to security reasons, and I'm also not prepared to use ActiveX.
Any ideas?
Code: Select all
$max_size = $_POST['MAX_FILE_SIZE'];
$upload_size = $_FILES['yourFile']['size'];
if ($upload_size > $max_size) {
$error = "1";
$errormsg = "Uploaded file is too big!";
}btw, iv just got into php aswell and it probably has its faults but this is just how i went about doing a similar thing
Im using action="$_SERVER['PHP_SELF']" on my form. When the form submits, and I check the error and size values of my files, they are empty. I assume that the file was not uploaded due to the MAX_FILE_SIZE hidden field setting, and therefore there appears to be nothing in $_FILES to check errors agains. I keep on getting empty errors even though I am submitting too large files.
Flabbergasted i am!?!?
Flabbergasted i am!?!?
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
The script works perfectly when the image is within the proper file size constraint. However, the moment the file is larger than my MAX_FILE_SIZE setting, the $_FILES array does not get filled. So I can't manage to catch the error to display a user-friendly message to my not so very technically talented site visitor.
My page simply pops back, and is reset.
My page simply pops back, and is reset.