I am creating a PHP upload form for the first time. I realize that if the file exceeds the max file size specified in php.ini that I will lose ALL my $_POST variables, which I don't like, but I am resigned to it. What I want to do is DETECT when this has happened, present an error to the user, and force them to go back to a page where the workflow can kind of start again and my $_POST variables will be retained.
How can I detect when the file they're attempting to upload is too big? Or, even better, can I use javascript to cancel the form submission if the file is too big!?
here's my form:
Code:
<table>
<form action="JCAHO.php" method="post">
<TR><TD><input type="submit" value="Cancel file upload and go back"></TD></TR>
<?php print('<input type="hidden" name="user_id" value="'.$_POST['user_id'].'">');?>
</form>
<form enctype="multipart/form-data" action="upload.php" method="POST">
<TR><TD>
<?php print('<input type="hidden" name="user_id" value="'.$_POST['user_id'].'">');?>
<input type="hidden" name="action" value="upload">
<?php print('<input type="hidden" name="file_desc" value="'.$_POST['file_desc'].'">');?>
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
</TD></TR><TR><TD>
<input type="submit" value="Upload File" /></TD></TR>
</form>
</table>
from php.ini:
Code:
; Maximum size of POST data that PHP will accept.
post_max_size = 15M
Halp!