我想使用 S3 API将多个文件上传到亚马逊。
这是我的代码
<form method="POST" enctype="multipart/form-data" action="/uploadcontentintoamazone">
<input type="file" id="fileinputAllPages" name="files[]" multiple />
</form>
uploadcontentintoamazone.php
$allFiles = $_FILES['files'];
$s3 = S3Client::factory(array(
'key' => '*************************',
'secret' => '*************************'
));
foreach($allFiles['tmp_name'] as $file){
$pathToFileSingle = $file;
$destFilePath = 'destination file name';
$commands[] = $s3->getCommand('PutObject', array(
'Bucket' => 'application-data',
'Key' => $destFilePath.$file,
'SourceFile' => $pathToFileSingle,
'ACL' => 'public-read'
));
}
$s3->execute($commands);
foreach ($commands as $command) {
$result = $command->getResult();
}
API集成工作正常。但是上传临时文件而不是我上传的文件。
提前致谢
答案 0 :(得分:1)
尝试这种方式:
for($i=0; $i<count($_FILES['files']['name']); $i++) {
$pathToFileSingle = $_FILES['upload']['tmp_name'][$i];
$destFilePath = 'destination file name' . $_FILES['upload']['name'][$i];
$commands[] = $s3->getCommand('PutObject', array(
'Bucket' => 'application-data',
'Key' => $destFilePath,
'SourceFile' => $pathToFileSingle,
'ACL' => 'public-read'
));
}
答案 1 :(得分:0)
你正在迭代错误的数组,你需要这样做:
foreach($allFiles as $file) {
$pathToFileSingle = $file["tmp_name"];
$destFilePath = $file["name"];
(您也没有正确设置目标文件名)