I have included the file type check it the below code. If i select 2 files from allowed type and one file from not allowed type the code still save the allowed one and show the msg for the file type as well. I want if any file is other than the allowed one the code should not save any thing.
<?php
// Script written by Adam Khoury for the following video exercise:
// http://www.youtube.com/watch?v=7fTsf80RJ5w
if(isset($_FILES['file_array'])) {
$name_array = $_FILES['file_array']['name'];
$tmp_name_array = $_FILES['file_array']['tmp_name'];
$type_array = $_FILES['file_array']['type'];
$size_array = $_FILES['file_array']['size'];
$error_array = $_FILES['file_array']['error'];
for($i = 0; $i < count($tmp_name_array); $i++){
$fileext [$i] = explode('.', $name_array[$i]);
$fileactualext[$i] = strtolower(end($fileext[$i]));
$allowed = array("jpg","jpeg", "pdf");
if (in_array($fileactualext[$i], $allowed)) {
if(move_uploaded_file($tmp_name_array[$i], "test_uploads/".$name_array[$i])) {
echo $name_array[$i]."upload is complete<br>";
} else {
echo "move_uploaded_file function failed for ".$name_array[$i]."<br>";
}
} else {
header('location:file_type.php');
}
}
}
?>