I’m setting up a form to upload PDFs and having trouble figuring out the root of my problem.
I have a form on one page.
<form enctype="multipart/form-data" action="step3.php" method="post">
<label>Select Any PDF's For This Product <br /><span style="font-size:12px; margin-left: 4px;">(Must be pdf format. Max file size 60MB)</span></label><br /><br />
<input type="hidden" name="MAX_FILE_SIZE" value="60000" />
<input name="uploadedpdf1" type="file" /><br />
<input name="uploadedpdf2" type="file" /><br />
<input name="uploadedpdf3" type="file" /><br />
<input name="uploadedpdf4" type="file" /><br />
<input name="uploadedpdf5" type="file" /><br /><br>
<input type="submit" name="submit" value="Next Step" />
</form>
Then on the next page I’m using a long PHP script to upload and validate the files. My problem starts at the beggening of the script so I will post a very simplified version.
for ($i = 1; $i < 6; ++$i) {
$file = "uploadedpdf{$i}";
if($_FILES[$file]["name"]!="") {
$fileName = $_FILES[$file]["name"];
$fileTmpLoc = $_FILES[$file]["tmp_name"];
$fileType = $_FILES[$file]["type"];
$fileSize = $_FILES[$file]["size"];
$fileErrorMsg = $_FILES[$file]["error"];
}}
At this point I’m just getting information about the uploaded file to see if it can be uploaded.
I get back no value for $_FILES[$file][“tmp_name”] or $_FILES[$file][“type”].
$_FILES[$file][“size”] = 0
$_FILES[$file][“error”] = 2
But $_FILES[$file][“name”] works fine.
Why doesn’t my file have a size and how can I go about debugging the 2 errors?
Before accessing the information in
$_FILES, you should check theerrorentry. In your case, an error of 2 means the size of the uploaded file is greater than the numeric value of the POST fieldMAX_FILE_SIZE, typically set with a hidden input field. Check that this input field has the correctvalue, or remove it.