3
我目前正在構建一個Zend框架PHP Web服務,它將從Android手機上傳的圖像調整大小,並將其放入Amazon Web Services S3。如何將PHP圖像資源放入Amazon Web Services?
這裏是我的代碼:
$img = $_FILES['image'];
if(!$img)
{
return null;
}
if((($img['type'] == 'image/gif') ||
($img['type'] == 'image/jpeg') ||
($img['type'] == 'image/png')) &&
($img['size'] < 1048576))
{
if($img['error'] >0)
{
throw new Exception("image contain error ");
}
$size24 = 24;
//obtain the auth settings
$bootstrap = $this->getInvokeArg('bootstrap');
$awsConfigs = $bootstrap->getOption('aws');
$s3 = new Zend_Service_Amazon_S3($awsConfigs['appkey'], $awsConfigs['secretkey']);
$bucketName = 'item';
$folderName = 'image';
$perms = array(
Zend_Service_Amazon_S3::S3_ACL_HEADER =>
zend_service_amazon_s3::S3_ACL_PUBLIC_READ
);
$name = $bucketName.'/'. $folderName .'/'. uniqid() .'_'. Zend_Date::now()->toString('yyyyMMdd');
$smallPath = $name . '_32.png';
//resize and upload 24x24 image
$srcImg = imagecreatefrompng($img['tmp_name']);
$tmp = imagecreatetruecolor($size24, $size24);
list($oriWidth, $oriHeight) = getimagesize($img['tmp_name']);
imagecopyresampled($tmp, $srcImg, 0, 0, 0, 0, $size24, $size24, $oriWidth, $oriHeight);
//not working
imagepng($tmp, "tmp_32.png")
$smallret = $s3->putFile("tmp_32.png", $smallPath, $perms);
imagedestroy($tmp);
imagedestroy($srcImg);
}
else
{
throw new Exception("image size/format not qualified.");
}
我想辦法到圖像資源流轉,這樣我就可以使用$ S3-> putFileStream或putObject方法,但我不能找到有效的辦法。
任何想法??
你搖滾!有用! – VHanded 2012-03-28 02:27:41