I am using the following html form code to allow the user to select multiple files for upload.
<form action="uploadFiles.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file[]" multiple /><br>
<input type="submit" name="submit" value="submit" />
</form>
uploadFiles.php has the following code.
<?php
echo "uploadFiles.php" . "<br>";
print_r($_POST);
if(isset($_POST['submit']))
{
echo "Post submit" . "<br>";
if ($_FILES["file"]["error"][0] > 0)
{
echo "Error: " . $_FILES["file"]["error"][0] . "<br>";
}
else
{
echo "No. files uploaded : ".count($_FILES['file']['name'])."<br>";
echo "Upload: " . $_FILES["file"]["name"][0] . "<br>";
echo "Type: " . $_FILES["file"]["type"][0] . "<br>";
echo "Size: " . ($_FILES["file"]["size"][0] / 1024) . " kB<br>";
echo "Stored in: " . $_FILES["file"]["tmp_name"][0];
}
}
?>
For some reason, isset($_POST['submit']) always returns false. I get the following output
uploadFiles.php
Array( )
You aren't closing the input
tags. Particularly, you aren't closing the <input type="file" name="file[]" multiple>
tag, so possibly it isn't being added to the form's $_POST
array correctly, and is instead being added to the file
array. Just a guess.
The problem appears to be related to the size of the files. If the files are 11 MB in size, the post only works with one of them. If I select both $_POST is an empty array. If the files are half that size, the post works with both with the following code.
HTML
<form action="uploadFiles.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file[]" multiple="multiple"/></br>
<input type="submit" name="submit[]" value="submit" />
</form>
uploadFiles.php
<?php
if(isset($_POST['submit']))
{
if ($_FILES["file[]"]["error"] > 0)
{
echo "Error: " . $_FILES["file[]"]["error"] . "<br>";
}
else
{
$numFilesUploaded=count($_FILES['file']['name']);
echo "No. files uploaded : ".$numFilesUploaded."<br><br>";
for ($inc=0; $inc<$numFilesUploaded; ++$inc){
echo "File " . $inc . ": " . $_FILES["file"]["name"][$inc] . "<br>";
echo "Upload: " . $_FILES["file"]["name"][$inc] . "<br>";
echo "Type: " . $_FILES["file"]["type"][$inc] . "<br>";
echo "Size: " . ($_FILES["file"]["size"][$inc] / 1024) . " kB<br>";
echo "Stored in: " . $_FILES["file"]["tmp_name"][$inc];
echo "<br><br>";
}
}
}
?>