当我使用此功能创建具有指定链接的图像时,它不会直接显示 刷新后会出现
http://mysite.local/img/slide-image-321.jpg/369x360
是图片的链接
private function generate_cache($localpath, $from, $to, $width, $height) {
$tempFrom = pathinfo($from);
$tempTo = pathinfo($to);
$tempPathFrom = $localpath.$tempFrom['basename'];
$tempPathTo = $localpath.$tempTo['basename'];
// Amazon S3
$awsAccessKey = Zend_Registry::getInstance()->config->amazons3->awsAccessKey;
$awsSecretKey = Zend_Registry::getInstance()->config->amazons3->awsSecretKey;
$bucketName = Zend_Registry::getInstance()->config->amazons3->bucketName;
$s3 = new Zend_Service_Amazon_S3($awsAccessKey, $awsSecretKey);
// ..
if(file_get_contents('http://'.$bucketName.'.s3.amazonaws.com/'.$tempFrom['basename'])) {
$content = file_get_contents('http://'.$bucketName.'.s3.amazonaws.com/'.$tempFrom['basename']);
}
if(!file_put_contents($tempPathFrom, $content)){
echo "Failed to copy the file";
}
$resize = $this->_helper->imgResize($tempPathFrom);
$resize->resizeImage($width, $height);
$resize->saveImage($tempPathTo, 95);
if(!$s3->putFile($tempPathTo, $bucketName."/".$tempTo["basename"])){
echo "failed to put the resized image in s3";
} else {
// Deleting the local files
unlink($tempPathTo);
unlink($tempPathFrom);
}
}
答案 0 :(得分:0)
因为加载页面时,不会在服务器上创建图像。实际上它可能会在刷新之前创建,并会在刷新后显示。
答案 1 :(得分:0)
我找到了解决方案,我将最后一次上传到s3部分移到了这里,这是第一次从本地加载,我将它上传到s3并删除本地,当它们刷新或第二次从s3加载
if( file_exists($localpath.$tmp["basename"]) ) {
readfile($localpath.$tmp["basename"]);
self::upload_aws($localpath.$tmp["basename"], $bucketName."/".$tmp["basename"]);
} elseif($s3->getObject($bucketName."/".$tmp["basename"])){
echo $s3->getObject($bucketName."/".$tmp["basename"]);
}
public function upload_aws(){
if(!$s3->putFile($tempPathTo, $bucketName."/".$tempTo["basename"])){
echo "failed to put the resized image in s3";
} else {
// Deleting the local files
unlink($tempPathTo);
unlink($tempPathFrom);
}
}