I uploaded the file to my S3 bucket using the AWS SDK for PHP. As a test, I set up a scenario where I pick a file (it is restricted to be an png image), and it is uploaded as test.png. The upload works as there's a file in my bucket called test.png. But instead of opening a page where the image is viewable when I click the link, it initiates a download. The file type says text. After the download, I double click the file and it opens as an image (as it should).
Here is my upload code:
$temp = $_FILES['files']['tmp_name'][0];
require("../vendor/aws/aws-autoloader.php");
$s3 = Aws\S3\S3Client::factory(array(
'key' => $aws_access,
'secret' => $aws_secret
));
$result = $this->db->query('SELECT DEFAULT(`avatar`) FROM (SELECT 1) AS dummy LEFT JOIN users ON True LIMIT 1')->fetchAll()[0][0];
$avatar = $this->session->get('user')['avatar'];
try {
$result = $s3->putObject(array(
'Bucket' => $bucket,
'Key' => 'test.png',
'SourceFile' => $temp,
'ACL' => 'public-read'
));
echo $result['ObjectURL'];
} catch(Aws\S3\Exception\S3Exception $e) {
echo $e->getMessage();
}
if($avatar != $result) {
// delete current avatar and replace values in session var
}
Aucun commentaire:
Enregistrer un commentaire