I am trying to upload a file to a folder inside a s3 bucket. I am doing the following in PHP:
我正在尝试将一个文件上载到s3 bucket中的一个文件夹中。我正在用PHP做以下事情:
$name = $_FILES['file']['name'];
$size = $_FILES['file']['size'];
$tmp = $_FILES['file']['tmp_name'];
$bucket= $_POST['bucket'];
$actual_image_name = explode('.',$name)[0]."-".time().".".$ext;
$s3->putObjectFile($tmp, $bucket , $actual_image_name, S3::ACL_PUBLIC_READ);
The bucket name is a string sent to PHP and indicates a subfolder using a forward slash:
桶名是发送给PHP的字符串,它使用斜杠表示子文件夹:
'<bucket name>/<subfolder>'
however, when I upload a new image to my bucket, it is uploaded to the bucket root. How can I upload this file to the subfolder in my bucket?
然而,当我将一个新图像上传到我的桶时,它被上传到桶根。如何将该文件上载到bucket中的子文件夹?
Thx
谢谢
1 个解决方案
#1
21
The name of the sub folder should be added to the beginning of the filename and not to the end of the bucket name.
子文件夹的名称应该添加到文件名的开头,而不是bucket名称的末尾。
#1
21
The name of the sub folder should be added to the beginning of the filename and not to the end of the bucket name.
子文件夹的名称应该添加到文件名的开头,而不是bucket名称的末尾。