I'm trying to upload multiple files with for each loop. what should I use in the first parameter of move_uploaded_file() function in this case
foreach ($_FILES["prodImg"]["name"] as $pImage) {
$nbr++;
$col = 'image' . $nbr;
$fileName = basename($pImage);
$target_file = $target_dir . "" . $fileName;
$rqt = "UPDATE prodimages SET $col=? WHERE prodId= ? ";
$stmt = $con->prepare($rqt);
$stmt->execute(array($fileName, $pID));
move_uploaded_file($pImage, $target_file);
}
As you can see in the docs you can use $_FILES["prodImg"]["tmp_name"][$i]
:
foreach ($_FILES["prodImg"]["name"] as $i => $pImage) {
move_uploaded_file($_FILES["prodImg"]["tmp_name"][$i], /*..*/);
}
You can always var_dump($_FILES);
to see what it looks like.
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.