【问题标题】:How do I upload an image file in slim 3?如何在 slim 3 中上传图像文件?
【发布时间】:2017-04-08 16:23:21
【问题描述】:

我必须使用 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 类中的代码 this is my directory stucture of folder on server 怎么了?谁能帮忙?

【问题讨论】:

  • 您是否遇到任何错误?
  • i have to upload image file on server using slim 3。那么出了什么问题?它与 Android 有什么关系?
  • 无法打开流没有这样的文件或目录..这个错误存在
  • ???那个错误在哪里?而且你没有说它与 Android 有什么关系。

标签: php android html slim


【解决方案1】:

尝试图片的完整路径

示例:

file_put_contents("/testslim/v1/src/images/".$filenamePath,$decoded);

【讨论】:

    【解决方案2】:
    $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();
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-18
      • 2015-12-09
      • 2020-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多