//story image to s3 bucket
try {
$s3->putObject([
'Bucket' => $config['s3']['bucket'],
'Key' => "uploads/{$name_of_uploaded_file}",
'Body' => fopen($path_of_uploaded_file, 'rb'),
'ACL' => 'public-read'
]);
//remove the file
unlink($path_of_uploaded_file);
} catch(S3Exception $e){
die("there was an error");
}
//retrieve image url
$objects = $s3->getIterator('ListObjects', [
'Bucket' => $config['s3']['bucket']
]);
//put img url into variable so that it stores it into sql table
$photoLink = $s3->getObjectUrl($config['s3']['bucket'], $objects['Key']);
if (is_uploaded_file($_FILES['uploaded_file']['size'])){
//send items to pending database
//note already connected to db
//inserts in pending db
$sql = "INSERT INTO pending (id,photo,title,description,name) VALUES ('', :photo, :title, :description, :name)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':title', $title);
$stmt->bindParam(':photo', $photoLink);
$stmt->bindParam(':description', $story);
$stmt->bindParam(':name', $first_name);
$stmt->execute();
}else {
header('Location:index.php');
}
Как я могу получить PHP вытащить URL, так что он хранит например: http://www.amazonaws/bucket/image.jpg в моей колонке SQL базы данных фото?Получение URL изображения от амазонки s3 объекта ковшом
Сейчас мой веб-приложение дает мне эту ошибку: не может использовать объект типа AWS \ S3 \ итератора \ ListObjectsIterator, как массив в на линии 127
Большое вам спасибо. Я заработал. Если у кого-то есть такая же проблема, просто выполните описанные выше шаги, чтобы вытащить URL-адрес из изображения в вашем ковше. – Gianni