Télécharger le fichier sur amazon S3 avec PHP SDK

Je suis en train de télécharger une photo sur mon amazon S3 par leur SDK PHP. J'ai donc fait un petit script pour le faire. Cependant, mon script ne fonctionne pas et mon exception ne doit pas me renvoyer un message d'erreur.

Je suis nouveau avec AWS merci pour votre aide.

Voici le code :

Config.php

<?php 

return array(
'includes' => array('_aws'),
'services' => array(
  'default_settings' => array(
      'params' => array(
          'key'    => 'PUBLICKEY',
          'secret' => 'PRIVATEKEY',
          'region' => 'eu-west-1'
      )
    )
  )
);

?>

Index.php

 <?php


//Installing AWS SDK via phar
require 'aws.phar';

use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;

$bucket = 'infact';
$keyname = 'myImage';

//$filepath should be absolute path to a file on disk                      
$filepath = 'image.jpg';

//Instantiate the client.
$s3 = S3Client::factory('config.php');

//Upload a file.
try {

$result = $s3->putObject(array(
    'Bucket'       => $bucket,
    'Key'          => $keyname,
    'SourceFile'   => $filePath,
    'ContentType'  => 'text/plain',
    'ACL'          => 'public-read',
    'StorageClass' => 'REDUCED_REDUNDANCY'
));

 //Print the URL to the object.
    echo $result['ObjectURL'] . "\n";
} catch (S3Exception $e) {
    echo $e->getMessage() . "\n";
}

?>

EDIT : je suis maintenant en utilisant ce code mais sa ne marche toujours pas. Je n'ai même pas d'erreur ou un message d'exception.

    <?php

require 'aws.phar';

use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;

$bucket = 'infactr';
$keyname = 'sample';
//$filepath should be absolute path to a file on disk                      
$filepath = 'image.jpg';

//Instantiate the client.
$s3 = S3Client::factory(array(
    'key'    => 'key',
    'secret' => 'privatekey',
    'region' => 'eu-west-1'

    ));

try {
    //Upload data.
    $result = $s3->putObject(array(
        'Bucket' => $bucket,
        'Key'    => $keyname,
        'SourceFile'   => $filePath,
        'ACL'    => 'public-read',
        'ContentType' => 'image/jpeg'
    ));

    //Print the URL to the object.
    echo $result['ObjectURL'] . "\n";
} catch (S3Exception $e) {
    echo $e->getMessage() . "\n";
}

?>
Exécutez-vous ce à partir du Web ou de la ligne de commande ?
Sur le web, pourquoi?
Essayez à partir de la ligne de commande pour voir les erreurs.
Oui s3cmd. Vous n'avez pas besoin s3cmd pour tenter votre script. Il vous suffit d'exécuter: php <yourscript>.php
à partir de la ligne de commande Linux

OriginalL'auteur casusbelli | 2014-03-16