I'm trying to upload multiple files, by altering a script I once used to upload a single file.
The only changes I've made are to add more file input fields to the form. But when I submit the form to the script, it halts at where I check for errors. How do I proceed with multiple files?
$form = '<form action="imgProcess.php" method="post" enctype="multipart/form-data">';
$form .= '<div><input type="file" name="file[]"></div>';
$form .= '<div><input type="file" name="file[]"></div>';
$form .= '<div><input type="file" name="file[]"></div>';
$form .= '<div><input type="file" name="file[]"></div>';
$form .= '<div><input type="file" name="file[]"></div>';
$form .= '<input type="hidden" name="handle" value="testHandle" />';
$form .= '<input type="submit">';
$form .= '</form>';
imgProcess.php
if($_FILES && isset($_POST['handle'])) {
$numFiles = count($_FILES['file']['tmp_name']);
echo $numFiles;
$handle = $_POST['handle'];
echo $handle;
// Halt on errors
if($_FILES['file']['error'] == 0) {
} else {
echo 'There were errors<br>';
print_r( $_FILES['file']['error'] );
}
} else {
echo 'Error 1';
}
//
There were errors
Array ( [0] => 0 [1] => 0 [2] => 4 [3] => 4 [4] => 4 )
move_uploaded_file()?foreachloop.