簡體   English   中英

如何在php mysql中使用重命名上傳多個圖像?

[英]How to upload multiple image with rename in php mysql?

我正在嘗試下面的代碼,使用php mysql上傳帶有數據庫的多個圖像,但是無法正常工作,請幫助我如何在php mysql中上傳多個圖像。 和即將到來的錯誤558d45b0b348a

注意:未定義的變量:第37行的D:\\ xampp \\ htdocs \\ app \\ db.php中的sql

查詢失敗!

<?php
    session_start();
    include_once('configuration.php');
    include_once('db.php');
        if (isset($_REQUEST['submit'])){
        echo $uname = uniqid();
            move_uploaded_file($_FILES["shop_img"]["tmp_name"][0],
             "uploaded/" . $_FILES["shop_img"]["name"][0]);
          $sql="INSERT INTO shop_list ('shop_img') 
            VALUES (:shop_img);";
            $sql_result = $db->queryPrepared($sql,array(
                ':shop_img' =>$_FILES["shop_img"]["name"][0]
            ));

            $lastId = $db->last_insert_id();
            print_r($_FILES);
            exit;
            foreach($_FILES['shop_img']['name'] as $k=>$v){
                $type = $_FILES['shop_img']['type'][$k];
                $name = $_FILES['shop_img']['name'][$k];
                $temp_name = $_FILES['shop_img']['tmp_name'][$k];
                $imgUniqName = uniqid().'.'.$type;
                $sqlImg = "INSERT INTO shop_images (shop_id, image) 
                VALUES (:shop_id, :img_name);";
                $sqlImgResult = $db->queryPrepared($sqlImg,array(
                ':shop_id' => $lastId,
                ':img_name' => $name
                ));
                move_uploaded_file($temp_name,"uploaded/" . $name);
                }
            $msg = "<b style='color: green;'>Image upload sucessfully</b>";
        }
    ?> 
<form action="" enctype="multipart/form-data" method="post">
    <?php if(isset($msg)) echo $msg; ?>
    <h3><a>Store Image</a></h3>
    <table>
        <tr>
            <td>Store</td>
            <td><input type="file" class="form-control" name="shop_img[]" id="shop_img" required="true" multiple /></td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td><input type="submit" value="Submit" name="submit" class="btn" /></td>
        </tr>
    </table>
</form>
<?php
session_start();
include_once('configuration.php');
include_once('db.php');
    if (isset($_REQUEST['submit'])){
        $sqlMax = "SELECT * FROM `shop_list` ORDER BY `shop_id` DESC LIMIT 0, 1"; 
        $sqlMaxResult = $db->fetchQuery($sqlMax);
        $maxId = (int)$sqlMaxResult[0]['shop_id'] + 1;
        $imageList = array();

        foreach($_FILES['shop_img']['name'] as $k=>$v){
            $type = $_FILES['shop_img']['type'][$k];
            $name = $_FILES['shop_img']['name'][$k];
            $temp_name = $_FILES['shop_img']['tmp_name'][$k];
            $imgStr = $maxId.'-'.$name;
            $imgUniqName = uniqid().'.'.$type;
                if(move_uploaded_file($temp_name,"uploaded/" . $name)){
                    array_push($imageList,$imgStr);
                }
            }
          $sql="INSERT INTO `shop_list` (`shop_img`)
            VALUES (:shop_img);";
            $sql_result = $db->queryPrepared($sql,array(
                ':shop_img' =>implode("#",$imageList)
            ));
        $msg = "<b style='color: green;'>Image upload sucessfully</b>";
    }
?> 
<form action="" enctype="multipart/form-data" method="post">
    <?php if(isset($msg)) echo $msg; ?>
    <h3><a>Store Image</a></h3>
    <table>
        <tr>
            <td>Store</td>
            <td><input type="file" class="form-control" name="shop_img[]" id="shop_img" required="true" multiple /></td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td><input type="submit" value="Submit" name="submit" class="btn" /></td>
        </tr>
    </table>
</form>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM