Error setting up a form to uplaod PDFs
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"开发者_StackOverflow中文版];
}}
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?
The file is too big. According to the error number (you can see a list on the manual):
UPLOAD_ERR_FORM_SIZE
Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive
that was specified in the HTML form.
Yours is
<input type="hidden" name="MAX_FILE_SIZE" value="60000" />
Edit after comment:
the size is specified in bytes, so 60 MB = 61,440,000. Also, be careful to have the php INI settings that allows such a size (directive *upload_max_filesize*), and that it doesn't exceed your time limit.
Before accessing the information in $_FILES
, you should check the error
entry. In your case, an error of 2 means the size of the uploaded file is greater than the numeric value of the POST field MAX_FILE_SIZE
, typically set with a hidden input field. Check that this input field has the correct value
, or remove it.
精彩评论