简体   繁体   中英

Uploading multiple files - Notice: Array to string conversion in

include "host.php";

$name = $_POST['name'];
$size = $_FILES["files"]["size"];
$type = $_FILES["files"]["type"];
$error = $_FILES["files"]["error"];
$lista = $_FILES["files"]["name"];

foreach ($lista as $nome_immagine) {
   $file = basename($nome_immagine);
   $uploadfile = "photo1/$file";
   echo $uploadfile;
   $temp = $_FILES["files"]["tmp_name"];
    mysql_query("INSERT INTO prova (gruppo, img) VALUES ('$name', '$file')") or die(mysql_error());
    move_uploaded_file($temp, $uploadfile);
    error_reporting(E_ALL); 
}

### Chiudiamo il Database ###
mysql_close($conn_host);

This is a uploading multiple files. Give me this error:

Notice: Array to string conversion in...

Here: move_uploaded_file($temp, $uploadfile);

Why?

Since you're uploading multiple files, $_FILES["files"]["tmp_name"] is an array, so you need to index it just like all the other $_FILES elements.

foreach ($lista as $index => $nome_immagine) {
    $file = basename($nome_immagine);
    $uploadfile = "photo1/$file";
    echo $uploadfile;
    $temp = $_FILES["files"]["tmp_name"][$index];
    mysql_query("INSERT INTO prova (gruppo, img) VALUES ('$name', '$file')") or die(mysql_error());
    move_uploaded_file($temp, $uploadfile);
    error_reporting(E_ALL); 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM