簡體   English   中英

如何在slim 3中上傳圖片文件?

[英]How do I upload an image file in slim 3?

我必須使用SLIM 3在服務器上上傳圖像文件。我想將文件路徑保存在表中,並將相應圖像保存在服務器上的文件夾中

 $filenamePath = md5(time().uniqid()).".jpg";
        $decoded=base64_decode($image);
        file_put_contents("images/".$filenamePath,$decoded);

        $sth = $this->db->prepare("UPDATE orders set status =:status,
                                      total_amount=:amount,created_at=:date1,receipt=:path WHERE id=:orderId");
        $sth->bindParam("orderId",$orderid );
        $sth->bindParam("status", $status);
        $sth->bindParam("amount", $amount);
        $sth->bindParam("date1", $date);
        $sth->bindParam("path", $filenamePath);
        $sth->execute();

這是我在slim 3類中的代碼, 這是我在服務器上的文件夾的目錄結構 什么地方出了錯? 有人可以幫忙嗎?

嘗試完整的圖像路徑

例:

file_put_contents("/testslim/v1/src/images/".$filenamePath,$decoded);
$filenamePath = md5(time().uniqid()).".jpg";
    $decoded=base64_decode($image);
    file_put_contents("../images/".$filenamePath,$decoded);

    $sth = $this->db->prepare("UPDATE orders set status =:status,
                                  total_amount=:amount,created_at=:date1,receipt=:path WHERE id=:orderId");
    $sth->bindParam("orderId",$orderid );
    $sth->bindParam("status", $status);
    $sth->bindParam("amount", $amount);
    $sth->bindParam("date1", $date);
    $sth->bindParam("path", $filenamePath);
    $sth->execute();

只需更改上述代碼中的路徑,並授予圖像文件夾權限

暫無
暫無

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

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