I have this code and it shows me this errors, and I don´t know how to solve it!!
Warning: basename() expects parameter 1 to be string, array given in C:\AppServ\www\quieromiauto\subida.php on line 14
Warning: getimagesize(Array) [function.getimagesize]: failed to open stream: No such file or directory in C:\AppServ\www\quieromiauto\subida.php on line 19
File is not an image.
Sorry, file already exists.
Sorry, your file is too large.
Sorry, only JPG, JPEG, PNG & GIF files are allowed.
Sorry, your file was not uploaded.
<?
$target_dir = "img/";
$target_file = $target_dir . basename($_FILES["subir"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["reg_auto"])) {
$check = getimagesize($_FILES['subir']["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES['subir']["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES['subir']["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES['subir']["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
$brand = $_POST['marca'];
$modelo = $_POST['modelo'];
$kilometros = $_POST['km'];
$comb = $_POST['Combustible'];
$city = $_POST['ciudad'];
$price = $_POST['precio'];
$estado = $_POST['estado'];
$year = $_POST['anio'];
$f1 = $_FILES['subir']['name'][0];
$f2 = $_FILES['subir']['name'][1];
$f3 = $_FILES['subir']['name'][2];
$f4 = $_FILES['subir']['name'][3];
$f5 = $_FILES['subir']['name'][4];
$tecnica = $_POST['ficha'];
$provincia = $_POST['prov'];
$dest = $_POST['destacado'];
$fecha = date("d/m/Y");
$sql = "INSERT INTO tblPublicaciones (IdUsuario, Marca, Modelo, Año, Precio, Kilometros, Provincia, Ciudad, Destacado, Estado, Combustible, FichaTecnica, Foto1, Foto2, Foto3, Foto4, Foto5, FechaPublicacion, Consultas, Visitas, Actividad) VALUES('".$_SESSION['IdUsuario']."','".$brand."','".$modelo."','".$anio."','".$price."','".$kilometros."', '".$provincia."','".$city."', '".$dest."','".$estado."','".$comb."','".$ficha."','".$f1."','".$f2."','".$f3."','".$f4."','".$f5."', '".$fecha."')";
}
//echo "<script type='text/javascript'>window.location.href = 'home.php'</script>";
?>
And the html input file upload is:
<input type="file" class="foto1 form-control" name="subir[]" required multiple><br>