错误"数组到字符串转换" - 使用图像上载查询数据库

时间:2014-10-10 20:08:17

标签: php mysql

剧本:

<?php

    include("connect.php")

?>


<?php
if (isset($_POST['submit'])) {
    $j = 0; //Variable for indexing uploaded image 

    $target_path = "uploads/"; //Declaring Path for uploaded images

    for ($i = 0; $i < count($_FILES['file']['name']); $i++) {//loop to get individual element from the array

        $validextensions = array("jpeg", "jpg", "png");  //Extensions which are allowed
        $ext = explode('.', basename($_FILES['file']['name'][$i]));//explode file name from dot(.) 
        $file_extension = end($ext); //store extensions in the variable

        $target_path = $target_path . md5(uniqid()) . "." . $ext[count($ext) - 1];//set the target path with a new name of image
        $j = $j + 1;//increment the number of uploaded images according to the files in array       

      if (($_FILES["file"]["size"][$i] < 100000) //Approx. 100kb files can be uploaded.
                && in_array($file_extension, $validextensions)) {
            if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) {//if file moved to uploads folder
                echo $j. ').<span id="noerror">Image uploaded successfully!.</span><br/><br/>';
            } else {//if file was not moved.
                echo $j. ').<span id="error">please try again!.</span><br/><br/>';
            }
        } else {//if file size and file type was incorrect.
            echo $j. ').<span id="error">***Invalid file Size or Type***</span><br/><br/>';
        }
    }


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

}
?>

错误讯息:

Notice: Array to string conversion in C:\xampp\htdocs\gallerysite\multiple_image_upload\upload.php on line 37

这是这一部分:

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

此脚本还使用javascript进行多个图片上传。

我希望将文件名插入MySQL数据库,但我收到上面的错误消息。

我一直在看教程,教程也使用&#34; $ _ FILES [&#39; file&#39;] [&#39; name&#39;]&#34;在查询字符串中,将文件名插入数据库。

有什么建议吗?

0 个答案:

没有答案