I have an html form, including an input file element. The form is processed by a php script. Most of the time, everything works fine — I can access the form data through $_POST and $_FILES, I can check the data submitted and I can manipulate the file. The action on the form is set to return to the same page as that on which the form appears.
However, I am unable to process anything when the user tries to upload a file which is too large. This is what happens:
- Nothing gets uploaded and the page reloads.
- $_FILES['uploadFile']['error'] is null, so I can't catch the error.
- isset($_POST['submit']) is false, so I can't process the input.
- There is no error message.
My form looks like this:
<form action="hwsa.html?form[id_assignment]=<?php echo($id_assignment); ?>" method="post" enctype="multipart/form-data" class="assignment-submission">
<p>Select file to upload. N.B. Only pdf files allowed; maximum size 5 MB.</p>
<input type="hidden" name="MAX_FILE_SIZE" value="5120000" />
<input type="file" name="uploadFile" id="assignment-file">
</p>
<p>
<input type="submit" name="submit" value="Submit" class="btn-reverse">
<input type="submit" name="submit" value="Cancel" class="btn-reverse">
</p>
</form>
I can process other errors, like using the wrong file type, in a block like this:
If (isset($_POST['submit']))
{
If ($_POST['submit']=='Cancel')
{
//Process cancel
}
If ($_POST['submit']=='Submit')
{
$size=$_FILES['uploadFile']['size'];
$sizeWarning = ($_FILES['uploadFile']['size'] > 5120000);
$fileType = strtolower(pathinfo($_FILES['uploadFile']['name'], PATHINFO_EXTENSION));
$typeWarning = ($fileType != 'pdf');
$emptyWarning = ($_FILES['upLoadFile']['size'] == 0);
// Process errors or process successful upload.
}
}
Any help would be greatly appreciated!
Thank you in advance.