![](/img/trans.png)
[英]Amazon S3 PHP Class, can I upload a file directly to a folder in a bucket
[英]AWS S3 PHP can I upload a file directly to a folder in a bucket
使用php sdk將文件直接上傳到AWS S3中的文件夾的語法是什么?
我成功使用以下方法上傳到存儲桶:
$response = $s3->create_object($bucket, $file_name, array('fileUpload' => $file_path))
tx!
試試這個
$s3->create_object($bucket, 'folder/filename', $options)
只需做一件事,添加'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->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.