i give users the option as to how much file upload fields they want to display, these first two actions just clean that information up. hope this is more clear, this is my exact code.
PHP Code:
//get amount of form fields chosen
$count = count($_FILES['userfile']['name']);
//clean up FILES array
for( $i=0; $i<$count; $i++ ) {
if( $_FILES['userfile']['error'][$i] != 0 ){
unset($_FILES['userfile']['name'][$i]);
unset($_FILES['userfile']['type'][$i]);
unset($_FILES['userfile']['tmp_name'][$i]);
unset($_FILES['userfile']['error'][$i]);
unset($_FILES['userfile']['size'][$i]);
}
}
//re-value the file name array
$name_array = array_values($_FILES['userfile']['name']);
$type_array = array_values($_FILES['userfile']['type']);
$tmp_array = array_values($_FILES['userfile']['tmp_name']);
$error_array = array_values($_FILES['userfile']['error']);
$size_array = array_values($_FILES['userfile']['size']);
//make monster array
$monster = array("name" => $name_array, "type" => $type_array, "tmp_name" => $tmp_array, "error" => $error_array, "size" => $size_array);
//update count
$count = count($monster['name']);
//make dir
mkdir($uploaddir."order".$order_id, 0777);
$fdir = $uploaddir."order".$order_id."/";
chmod( $fdir, 0777 );
//move files
for( $i=0; $i<$count; $i++ ) {
if (move_uploaded_file($monster['tmp_name'][$i], $fdir . $monster['name'][$i])) {
print "File ".$monster['name'][$i]." is valid, and was successfully uploaded.<br>\n";
}
else {
print "File did not upload";
}
Bookmarks