Prendendo spunto dal web, ho provato questo codice per il multiupload delle foto.
Unica cosa, i dati non riesco ad inserirli nel db e non so come mai.
tabella db:
id(autoincrement) | nome | prezzo | immagine | img2 | img3 | img4
lo script è:
Unica cosa, i dati non riesco ad inserirli nel db e non so come mai.
tabella db:
id(autoincrement) | nome | prezzo | immagine | img2 | img3 | img4
lo script è:
PHP:
<?php
if(isset($_FILES['files'])){
$errors= array();
foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){
$file_name = $key.$_FILES['files']['name'][$key];
$file_size =$_FILES['files']['size'][$key];
$file_tmp =$_FILES['files']['tmp_name'][$key];
$file_type=$_FILES['files']['type'][$key];
if($file_size > 2097152){
$errors[]='File size must be less than 2 MB';
}
$sql = new mysqli("localhost", "root", "", "my_luca");
$query = "INSERT into prova ('nome','prezzo','immagine','img2','img3','img4') VALUES('a','0','$file_name','a','a','a')";
$desired_dir="user_data";
if(empty($errors)==true){
if(is_dir($desired_dir)==false){
mkdir("$desired_dir", 0700); // Create directory if it does not exist
}
if(is_dir("$desired_dir/".$file_name)==false){
move_uploaded_file($file_tmp,"user_data/".$file_name);
}else{ //rename the file if another one exist
$new_dir="user_data/".$file_name.time();
rename($file_tmp,$new_dir) ;
}
mysql_query($query);
}else{
print_r($errors);
}
}
if(empty($error)){
echo "Success";
}
}
?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST" enctype="multipart/form-data">
<input type="file" name="files[]" multiple/>
<input type="submit"/>
</form>