duandu6497 2018-02-28 14:58
浏览 28
已采纳

PHP上传到AWS S3会产生错误的目标路径

I want to upload an image file to my S3 storage using PHP. I use this helper library: https://github.com/psugand/CodeIgniter-S3

This is my PHP code:

$this->s3->putObject($this->s3->inputFile($tmp), 'dreamboks-assets-2017', '/test_example/' . basename($_FILES["userfile"]['tmp_name']), S3::ACL_PUBLIC_READ);

The problem is S3 always creating an empty directory first before my desire directory (test_example/).

Screenshot: Screenshot S3

How to avoid the unwanted empty directory? Is there any problem with my destination path parameter?

  • 写回答

1条回答 默认 最新

  • dongrong8972 2018-02-28 15:33
    关注

    You need to use a relative path. The API wrapper you're using is probably being thrown off by the leading /. So use it like this:

    $this->s3->putObject(
        $this->s3->inputFile($tmp), 
        'dreamboks-assets-2017', 
        'test_example/' . basename($_FILES["userfile"]['tmp_name']), // relative path
        S3::ACL_PUBLIC_READ
    );
    

    Changed the formatting a bit to emphasize the change

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码