我正在尝试从 HTML 表单中获取 Array 中的 FILES,并将它们存储在数据库中。我编写了以下代码,它给了我很多错误消息。看起来主要问题是它没有将数组转换为字符串。
请指导我。
Line 27 : $image_name= $_FILES["files"]["name"]; LINE 29: $random_name= rand().$_FILES["files"]["name"];
$_FILES 输出
Array ( [files] => Array ( [name] => Array ( [0] => Bracelet_Gold.jpg [1] => Necklaces_Silver.png [2] => Brooches_Gold.png ) [type] => Array ( [0 ] => image/jpeg [1] => image/png [2] => image/png) [tmp_name] => 数组 ([0] => F:\xampp\tmp\php599C.tmp [1] => F:\xampp\tmp\php599D.tmp [2] => F:\xampp\tmp\php599E.tmp ) [错误] => 数组 ( [0] => 0 [1] => 0 [2] => 0 ) [大小] => 数组 ( [0] => 7150 [1] => 37867 [2] => 314296 ) )
<body>
<form action="" method="post" enctype="multipart/form-data">
<p>Pictures:
<input type="file" name="files[]" />
<input type="file" name="files[]" />
<input type="file" name="files[]" />
<input type="submit" value="Send" />
</p>
</form>
</body>
</html>
<?php
include 'connect.php';
if (isset($_FILES['files'])
|| ($_FILES["files"]["type"] == "image/jpeg"))
{
foreach($_FILES['files']['tmp_name'] as $key=> $tmp_name)
{
//echo $tmp_name."<br>";
echo $image_name= $_FILES["files"]["name"];
$random_name= rand().$_FILES["files"]["name"];
$folder="upload/products/" .$random_name;
move_uploaded_file($_FILES["files"]["tmp_name"],
"upload/products/" . $random_name);
$sql = "Insert into product_images (product_id,name,images)
VALUES ($current_id,'$image_name', '$folder')";
if (mysql_query($sql))
{
echo 'Done';
}
else
{
echo mysql_error();
}
}
}
?>
注意:第 27 行 F:\xampp\htdocs\CMS\array_upload.php 中的数组到字符串转换 数组注意:第 29 行 F:\xampp\htdocs\CMS\array_upload.php 中的数组到字符串转换
警告:move_uploaded_file() 期望参数 1 为字符串,数组在第 34 行的 F:\xampp\htdocs\CMS\array_upload.php 中给出