如何在 slim 3 中上传图像文件?

How do I upload an image file in slim 3?

我必须使用 slim 3 在服务器上上传图像文件。我想将文件路径保存在 table 中,并将相应图像保存在服务器上的文件夹中

 $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();

This is my code in slim 3 class this is my directory stucture of folder on server What is wrong? Can anyone help?

尝试图片的完整路径

示例:

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();

只需更改上面代码中的路径并授予图像文件夹权限