Amazon s3, upload a file to a folder in a bucket

I am trying to upload a file to a folder inside the s3 bucket. I am doing the following in 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 slash:

 '<bucket name>/<subfolder>' 

however, when I load a new image into my bucket, it loads into the root of the bucket. How to upload this file to a subfolder in my bucket?

thanks

+5
source share
1 answer

The subfolder name should be appended to the beginning of the file name, and not to the end of the bucket name.

+21
source

Source: https://habr.com/ru/post/1210306/


All Articles