Forum Moderators: coopster
Typically people will load each of the 5 image fields with an image over 2mb and wonder why the page timed-out or is blank after a couple of minutes.
Can PHP or something check this before the form gets rolling, then warn them about the size or time it will take to load these images?
Good luck! :)
Can PHP or something check this before the form gets rolling, then warn them about the size or time it will take to load these images?
PHP, being a server-side language, cannot do anything until the file has been sent (closing the barn doors after the horses have run away).
JavaScript does not allow any interaction with the file system (Thank God!), so it can't help you.
$size = $_FILES['userfile']['size'];
if($size > 30000) {
echo 'File size too large!';
exit();
}
And Henry brings up a good point also. Make sure that you are receiving the type of file that you want to be receiving by checking
$_FILES['userfile']['type'] for the appropriate mime types. :)
Try searching for this in google
"php asynchronous image upload"
(without the quotes)
You could modify this to just do a check and if it's to big, return a message of some sort, or if it's big enough, let it continue to upload to a temp directory, then when they submit, move the image to a new directory.
you should review this thread
Coopster explains [webmasterworld.com] file upload process
that thread has many good info.
It seems that the subtitle escaped me :)
It is supposed to be an advisory to the browser not to upload a larger file than specified, but in my experience it doesn't work. Maybe you'll have better luck? ;)
It should work correctly, but on your action page you would want to put something like this:
if($_FILES['userfile']['error'] === 0) {
//proceed with upload
} else {
//an error has occurred
}
Error Messages Explained [us2.php.net].
I learn something every day. ;)
P.S. Don't forget that the hidden input stated above must come before the file input.