【发布时间】:2015-02-11 01:08:19
【问题描述】:
这是我的代码
function s3UploadImage($tmpFile,$file) {
$tmpLoc=$bucket.$file;
$s3 = new S3(awsAccessKey, awsSecretKey);
$s3->putBucket($bucket, S3::ACL_PUBLIC_READ);
if($s3->putObjectFile($tmpFile, $bucket , $tmpLoc, S3::ACL_PUBLIC_READ, array(
"Cache-Control" => "max-age=94608000",
"Expires" => gmdate("D, d M Y H:i:s T",
strtotime("+3 years")),$contentType) )
{
$msg = "S3 Upload Successful.";
// $s3file='https://xxxxxxxxxxxxx.xxxxxxx/'.$tmpLoc;
$s3file='https://xxxxxxxxxxxxxxx.xxxxxxx/'.$tmpLoc;
// echo "<img src='$s3file'/>";
echo 'S3 File URL:'.$s3file;
$status=true;
}
else{
$msg = "S3 Upload Fail.";
$status=false;
}
return $status;
}
在这段代码中,我添加了 array("Cache-Control" => "max-age=31536000","Expires" => gmdate("D, d MYH:i:s T", strtotime("+3 years ")) 它的工作正常。但它像这样添加
x-amz-meta-cache-control public,max-age=31536000
x-amz-meta-expires Wed, 11 Dec 2017 10:47:59 GMT
在谷歌页面速度测试工具中仍然显示未指定过期 但是如果我使用 s3 browser 等工具直接在 s3 中添加 http Header 。它工作正常。它像这样添加
Expires Wed, 15 May 2019 20:00:00
Cache-Control max-age=31536000, public
使用api如何添加这样的http headers。
【问题讨论】:
标签: php http amazon-web-services amazon-s3 http-headers