此代码有效,它将多个图像上传到文件夹,但在将图像信息插入数据库时,它仅插入 1 个名称。如有任何帮助,我将不胜感激
#target folder
$target = 'image_uploads/';
if(isset($_FILES['image_name'])===true){
$files = $_FILES['image_name'];
for($x = 0 ; $x < count($files['name']); $x++){
$name = $files['name'][$x] ;
$temp_name = $files['tmp_name'][$x];
$move = move_uploaded_file($temp_name,$target.$name);
}
}
?>
<?php
try{
$con = new PDO('mysql:host=localhost;dbname=tish_database;charset=utf-8','root','');
$query="INSERT INTO tish_images(image_name)
VALUES(:image_name)";
$insert = $con->prepare($query);
$insert->execute(array(
':image_name'=>$name));
}catch(PDOException $e){
echo $e->getMessage();
}