我目前正在为我的网站编写一个后端页面,以允许管理员间接编辑数据库条目并上传照片。我正在使用 Amazon S3 来托管图像以使它们更快地加载,因此当我上传图像时,我必须首先将它们上传到服务器,然后从那里将它们发送到 Amazon 服务器。图像正确上传到服务器,但它们没有正确到达亚马逊的服务器。当我尝试访问亚马逊副本时,它似乎不存在。这是我用来上传图片的代码:
//Set up image validator
$upload = new Zend_File_Transfer();
$upload->addValidator('ImageSize', false, array('minwidth' => 100,
'maxwidth' => 1000,
'minheight' => 100,
'maxheight' => 1000), 'image')
->addValidator('Extension', false, 'jpg')
->addValidator('Count', false, array('min'=>0, 'max'=>2));
//Set up Amazon class
$s3 = new Zend_Service_Amazon_S3($my_aws_key, $my_aws_secret_key);
if($upload->isUploaded('image')){ //Pic was uploaded
if($upload->isValid('image')){ //Pic is valid
echo "Pic provided is valid.";
$upload->addFilter('Rename',array('target'=>BASE_PATH . "/public_html/items/{$item_id}_nsa.jpg",'overwrite'=>true));
$upload->receive();
$pic = BASE_PATH . "/public_html/items/{$item_id}_nsa.jpg";
try{
$s3->putObject("media.completeset.com/images/items/{$item_id}_nsa.jpg", $pic,
array(Zend_Service_Amazon_S3::S3_ACL_HEADER => Zend_Service_Amazon_S3::S3_ACL_PUBLIC_READ,
Zend_Service_Amazon_S3::S3_CONTENT_TYPE_HEADER => "image/jpeg"));
echo "Pic is uploaded.";
}
catch(Exception $e){
echo "Exception: ".$e->getMessage();
}
}
else{
echo "Pic is invalid.";
}
}
else{
echo "Pic isn't uploaded";
}
以及我的错误示例。本地工作副本和亚马逊副本。我以前从未与亚马逊合作过,所以我不知道问题是什么,如何弄清楚它是什么,或者如何解决它。任何对这 3 点的任何帮助将不胜感激。