I am trying to take FILES in Array from HTML form, and store them in database. I have written the following code and it is giving me many error messages. It looks like that the main problem is that it is not converting Array into string.
Kindly guide me.
Line 27 : $image_name= $_FILES["files"]["name"]; LINE 29: $random_name= rand().$_FILES["files"]["name"];
$_FILES Output
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] => Array ( [0] => F:\xampp\tmp\php599C.tmp [1] => F:\xampp\tmp\php599D.tmp [2] => F:\xampp\tmp\php599E.tmp ) [error] => Array ( [0] => 0 [1] => 0 [2] => 0 ) [size] => Array ( [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();
}
}
}
?>
Notice: Array to string conversion in F:\xampp\htdocs\CMS\array_upload.php on line 27 Array Notice: Array to string conversion in F:\xampp\htdocs\CMS\array_upload.php on line 29
Warning: move_uploaded_file() expects parameter 1 to be string, array given in F:\xampp\htdocs\CMS\array_upload.php on line 34
$_FILES["files"]["tmp_name"]
seems to be claimed an array. The next step is to dig up the documentation for$_FILES
- John Dvorak