Friday 15 June 2012

php - Error "Array to string conversion" - Query to Database with Image Upload -



php - Error "Array to string conversion" - Query to Database with Image Upload -

the script:

<?php include("connect.php") ?> <?php if (isset($_post['submit'])) { $j = 0; //variable indexing uploaded image $target_path = "uploads/"; //declaring path uploaded images ($i = 0; $i < count($_files['file']['name']); $i++) {//loop individual element array $validextensions = array("jpeg", "jpg", "png"); //extensions allowed $ext = explode('.', basename($_files['file']['name'][$i]));//explode file name dot(.) $file_extension = end($ext); //store extensions in variable $target_path = $target_path . md5(uniqid()) . "." . $ext[count($ext) - 1];//set target path new name of image $j = $j + 1;//increment number of uploaded images according files in array if (($_files["file"]["size"][$i] < 100000) //approx. 100kb files can uploaded. && in_array($file_extension, $validextensions)) { if (move_uploaded_file($_files['file']['tmp_name'][$i], $target_path)) {//if file moved uploads folder echo $j. ').<span id="noerror">image uploaded successfully!.</span><br/><br/>'; } else {//if file not moved. echo $j. ').<span id="error">please seek again!.</span><br/><br/>'; } } else {//if file size , file type incorrect. echo $j. ').<span id="error">***invalid file size or type***</span><br/><br/>'; } } ($i = 0; $i < count($_files['file']['name']); $i++) { $tqs = "insert images (`image_file`) values ('" . $_files['file']['name'] . "')"; $tqr = mysqli_query($dbc, $tqs); } } ?>

the error message:

notice: array string conversion in c:\xampp\htdocs\gallerysite\multiple_image_upload\upload.php on line 37

it part here:

for ($i = 0; $i < count($_files['file']['name']); $i++) { $tqs = "insert images (`image_file`) values ('" . $_files['file']['name'] . "')"; $tqr = mysqli_query($dbc, $tqs); }

this script uses javascript multiple image upload.

i looking insert file name mysql database, yet getting error message above.

i have been looking @ tutorials, tutorials utilize "$_files['file']['name']" in query string insert file name database.

any suggestions?

php mysql

No comments:

Post a Comment