[英]Upload an object by streaming the contents of a file AWS SDK PHP 2
I am to newbie to amazon s3. 我是Amazon S3的新手。 I downloaded zip into my project and unzipped it.
我将zip下载到我的项目中并解压缩。 Bucket is already created 'bucketToUpload'.
存储桶已创建为“ bucketToUpload”。 My code for upload a file is
我上传文件的代码是
require 'aws/aws-autoloader.php';
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;
use Aws\S3\Enum\CannedAcl;
$bucket = 'bucketToUpload';
$pathToFile = getcwd().'/s3_upload_file.doc';
if(file_exists($pathToFile)) {
try {
$client = S3Client::factory(array(
'key' => 'MYKEY',
'secret' => 'MYSECRETKEY',
'region' => 'us-west-1'
));
$client->waitUntilBucketExists(array('Bucket' => $bucket));
$result = $client->putObject(array(
'Bucket' => $bucket,
'Key' => 's3_upload_file.doc',
'SourceFile' => getcwd(),
'ACL' => CannedAcl::PRIVATE_ACCESS,
'Metadata' => array(
'Foo' => 'abc',
'Baz' => '123'
)
));
} catch (S3Exception $e) {
echo "The file was not uploaded: " . $e->getMessage();
}
var_dump($result);
}
I am getting Fatel error: Maximum execution time of 15 seconds exceeded. 我收到Fatel错误:超过15秒的最大执行时间。 Really don't know what am I doing wrong.
真的不知道我在做什么错。 Any help could be really appreciable.
任何帮助都是非常可观的。
Thanks 谢谢
I see a few things you may need to do. 我看到您可能需要做的几件事。
First , you are specifying 首先 ,您要指定
'SourceFile' => getcwd(),
When I think you probably meant to do 当我认为您可能打算做
'SourceFile' => $pathToFile,
Second , you are doing var_dump($result);
其次 ,您正在做
var_dump($result);
which will probably not show you what you are expecting to see. 可能不会显示您期望看到的内容。 Try
var_dump($result->toArray());
尝试
var_dump($result->toArray());
instead, but make sure to checkout the user guide page about response models for more information about working with results. 相反,但请确保签出有关响应模型的用户指南页面 ,以获取有关处理结果的更多信息。
Third , the error you are seeing Fatal error: Maximum execution time of 15 seconds exceeded
is related to PHP's max_execution_time
INI setting. 第三 ,您看到的错误
Fatal error: Maximum execution time of 15 seconds exceeded
与PHP的max_execution_time
INI设置有关。 You should increase that limit if needed. 如果需要,您应该增加该限制。 You can also use the set_time_limit function within a single process.
您也可以在单个进程中使用set_time_limit函数 。
I hope that helps! 希望对您有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.