问题
I'm trying to upload a file on my amazon S3 bucket via the PHP SDK. However my script doesn't work, I have a blank page without any error or exception message.
EDIT : After enabled "display_error" in php.ini. I have the error message below (looks like the sdk is not working on my side).
Thanks to @datasage . The problem was that aws.phar needs cURL to be installed on the machine to work.
sudo apt-get install php5-curl
<?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";
}
?>
Here is the error message that I get.
Notice: Use of undefined constant CURLE_COULDNT_RESOLVE_HOST - assumed 'CURLE_COULDNT_RESOLVE_HOST' in phar:///var/www/s3/aws.phar/Aws/S3/S3Client.php on line 242 Notice: Use of undefined constant CURLE_COULDNT_CONNECT - assumed 'CURLE_COULDNT_CONNECT' in phar:///var/www/s3/aws.phar/Aws/S3/S3Client.php on line 242 Notice: Use of undefined constant CURLE_PARTIAL_FILE - assumed 'CURLE_PARTIAL_FILE' in phar:///var/www/s3/aws.phar/Aws/S3/S3Client.php on line 242 Notice: Use of undefined constant CURLE_WRITE_ERROR - assumed 'CURLE_WRITE_ERROR' in phar:///var/www/s3/aws.phar/Aws/S3/S3Client.php on line 242 Notice: Use of undefined constant CURLE_READ_ERROR - assumed 'CURLE_READ_ERROR' in phar:///var/www/s3/aws.phar/Aws/S3/S3Client.php on line 242 Notice: Use of undefined constant CURLE_OPERATION_TIMEOUTED - assumed 'CURLE_OPERATION_TIMEOUTED' in phar:///var/www/s3/aws.phar/Aws/S3/S3Client.php on line 242 Notice: Use of undefined constant CURLE_SSL_CONNECT_ERROR - assumed 'CURLE_SSL_CONNECT_ERROR' in phar:///var/www/s3/aws.phar/Aws/S3/S3Client.php on line 242 Notice: Use of undefined constant CURLE_HTTP_PORT_FAILED - assumed 'CURLE_HTTP_PORT_FAILED' in phar:///var/www/s3/aws.phar/Aws/S3/S3Client.php on line 242 Notice: Use of undefined constant CURLE_GOT_NOTHING - assumed 'CURLE_GOT_NOTHING' in phar:///var/www/s3/aws.phar/Aws/S3/S3Client.php on line 242 Notice: Use of undefined constant CURLE_SEND_ERROR - assumed 'CURLE_SEND_ERROR' in phar:///var/www/s3/aws.phar/Aws/S3/S3Client.php on line 242 Notice: Use of undefined constant CURLE_RECV_ERROR - assumed 'CURLE_RECV_ERROR' in phar:///var/www/s3/aws.phar/Aws/S3/S3Client.php on line 242 Fatal error: Uncaught exception 'Guzzle\Common\Exception\RuntimeException' with message 'The PHP cURL extension must be installed to use Guzzle.' in phar:///var/www/s3/aws.phar/Guzzle/Http/Client.php:70 Stack trace: #0 phar:///var/www/s3/aws.phar/Aws/Common/Client/AbstractClient.php(78): Guzzle\Http\Client->_construct('//s3-eu-w...', Object(Guzzle\Common\Collection)) #1 phar:///var/www/s3/aws.phar/Aws/Common/Client/ClientBuilder.php(252): Aws\Common\Client\AbstractClient->_construct(Object(Aws\Common\Credentials\Credentials), Object(Aws\S3\S3Signature), Object(Guzzle\Common\Collection)) #2 phar:///var/www/s3/aws.phar/Aws/S3/S3Client.php(206): Aws\Common\Client\ClientBuilder->build() #3 /var/www/s3/index2.php(19): Aws\S3\S3Client::factory(Array) #4 {main} thrown in phar:///var/www/s3/aws.phar/Guzzle/Http/Client.php on line 70
来源:https://stackoverflow.com/questions/22882782/upload-a-file-on-amazon-s3-with-php-sdk