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

问题描述 投票:1回答:1

我想使用PHP将图像文件上传到我的S3存储。我使用这个帮助库:https://github.com/psugand/CodeIgniter-S3

这是我的PHP代码:

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

问题是S3总是在我的欲望目录(test_example /)之前创建一个空目录。

屏幕截图:Screenshot S3

如何避免不必要的空目录?我的目标路径参数有问题吗?

php codeigniter amazon-web-services amazon-s3
1个回答
0
投票

您需要使用相对路径。您正在使用的API包装器可能被领先的/抛弃了。所以像这样使用它:

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

稍微更改了格式以强调更改

© www.soinside.com 2019 - 2024. All rights reserved.