Php 如何在yii框架中存储S3中的图像
我正在使用yii框架,并尝试在S3中上传图像 使用CuploatedFile将文件存储在本地服务器中。我需要在亚马逊发送新的图像,因为服务器已满 图像已发送到s3服务器,但已损坏,无法打开 ArticleController.php Image.php 我还尝试了file\u get\u contents$image->getTempName,但我不知道出了什么问题Php 如何在yii框架中存储S3中的图像,php,file-upload,amazon-web-services,yii,amazon-s3,Php,File Upload,Amazon Web Services,Yii,Amazon S3,我正在使用yii框架,并尝试在S3中上传图像 使用CuploatedFile将文件存储在本地服务器中。我需要在亚马逊发送新的图像,因为服务器已满 图像已发送到s3服务器,但已损坏,无法打开 ArticleController.php Image.php 我还尝试了file\u get\u contents$image->getTempName,但我不知道出了什么问题 public function actionCreate() { $model = new Article(); if(i
public function actionCreate() {
$model = new Article();
if(isset($_POST['Article']) {
$model->attributes = $_POST['Article']
$model->image = CUploadedFile::getInstance($model, 'image');
$image = new Image();
$uploadSuccess = $image->insertNewPicture($model->image);
if ($uploadSuccess)
$model->save();
}
}
public function insertNewPicture($image) {
if (empty($image))
return false;
$s3Client = S3Client::factory(Yii::app()->params['s3']);
try {
$success = $s3Client->upload('my_bucket',
'test.png', fopen($image->getTempName(), 'rb'),
'public-read');
} catch (Exception $e) {
return false;
}
if (!$success)
return false;
return $this->save();
}