I am lowering the file name and checking for the file extension using explode()
but I keep getting these two errors: Warning: explode() expects parameter 2 to be string, array given
On this line: $tmp = explode('.', $_FILES['files']['name']);
and Warning: end() expects parameter 1 to be array, null given
on this line $file_ext = strtolower(end ($tmp));
(the second on comes from the first one).
I think this is the problem $file_name = count($_FILES['files']['name']);
specifically the count
part. because this is a file uploading script and I'm am giving someone the option to upload multiple images at a time. When I click the upload button the images still go in but I just get those two warnings. I tried all the other answers on here but none of them helped me so any suggestions ?
$date_time = date('Y-m-d_H-i-s');
$errors = [];
if(isset($_POST['submit'])) {
//if (isset($_POST['files'])) {
$file_name = count($_FILES['files']['name']);
$file_size = $_FILES['files']['size'];
$file_type = $_FILES['files']['type'];
$tmp = explode('.', $_FILES['files']['name']);
$file_ext = strtolower(end ($tmp));
$extensions = array("jpeg", "jpg", "png", "gif");
if(in_array($file_ext, $extensions) === false) {
$errors = "Only jpeg, jpg, png and gif files are allowed.";
}
if ($file_size > 95097152) {
$errors = 'File cannot be larger than 1MB';
}
//$files = array_filter($_FILES['upload']['name']); //something like that to be used before processing files.
// Count # of uploaded files in array
//$total = count($_FILES['files']['name']);
// Loop through each file
for( $i=0 ; $i < $file_name ; $i++ ) {
//Get the temp file path
//$tmpFilePath = $_FILES['files']['tmp_name'][$i];
$file_tmp = $_FILES['files']['tmp_name'][$i];
//Make sure we have a file path
if ($file_tmp != ""){
# code...
//Setup our new file path
$newFilePath = "./uploads/" . $_FILES['files']['name'][$i];
//Upload the file into the temp dir
if(move_uploaded_file($file_tmp, $newFilePath)) {
//Handle other code here
}
}
}
//}
}