[英]AWS S3 PHP can I upload a file directly to a folder in a bucket
What is the syntax for uploading a file directly to a folder in AWS S3 with the php sdk? 使用php sdk将文件直接上传到AWS S3中的文件夹的语法是什么?
I was successful in uploading to a bucket using: 我成功使用以下方法上传到存储桶:
$response = $s3->create_object($bucket, $file_name, array('fileUpload' => $file_path))
tx! tx!
试试这个
$s3->create_object($bucket, 'folder/filename', $options)
Simply do 1 thing, add 'path/' ex: If you have a folder 'videos' in a bucket then you have to add path like this in 'key' =>'videos/video-name-here'. 只需做一件事,添加'path /'例如:如果存储桶中有文件夹'videos',则必须在'key'=>'videos / video-name-here'中添加这样的路径。
try {
// Upload data.
$result = $s3Client->putObject([
'Bucket' => bucket-name,
'Key' => 'videos/video-name', //add path here
'Body' => fopen($video, 'r'),
'ACL' => 'public-read'
]);
print_r($result['ObjectURL']);
} catch (S3Exception $e) {
echo $e->getMessage() . PHP_EOL;
}
This is another way you can try 这是您可以尝试的另一种方法
$this->Aws->bucket = 'bucket'
$old_file = $dir. '/'.old_file_name;
$new_file = $dir. '/'.new_file_name;
$file_permission = 'private';
$this->Aws->upload($old_file , $new_file , $file_permission);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.