php - How to Convert Array into String in HTML Form? [Notice: Array to string conversion?] -
i trying take files in array html form, , store them in database. have written following code , giving me many error messages. looks main problem is not converting array 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'] $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 product_images (product_id,name,images) values ($current_id,'$image_name', '$folder')"; if (mysql_query($sql)) { echo 'done'; } else { echo mysql_error(); } } } ?>
notice: array string conversion in f:\xampp\htdocs\cms\array_upload.php on line 27 array notice: array string conversion in f:\xampp\htdocs\cms\array_upload.php on line 29
warning: move_uploaded_file() expects parameter 1 string, array given in f:\xampp\htdocs\cms\array_upload.php on line 34
$_files["files"]["tmp_name"] array of files receiving need do:-
move_uploaded_file($_files["files"]["tmp_name"][$key], "upload/products/" . $random_name);
or receiving current temp name in $tmp_name can use:-
move_uploaded_file($tmp_name, "upload/products/" . $random_name);
Comments
Post a Comment