-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCropAction.php
49 lines (45 loc) · 1.54 KB
/
CropAction.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace daimakuai\avatar;
/**
* @see 代码块中文网 http://www.daimakuai.com
* @author yt <431910788@qq.com>
* 头像上传组件
* 如何配置请到官网(代码块中文网:www.daimakuai.com)查看相关文章
*/
use Yii;
use yii\base\Action;
use yii\web\UploadedFile;
use yii\helpers\ArrayHelper;
class CropAction extends Action
{
public $config = [];
public function init()
{
$config = [
'bigImageWidth' => '200', //大图默认宽度
'bigImageHeight' => '200', //大图默认高度
'middleImageWidth'=> '100', //中图默认宽度
'middleImageHeight'=> '100',//中图图默认高度
'smallImageWidth' => '50', //小图默认宽度
'smallImageHeight' => '50', //小图默认高度
//头像上传目录
'uploadPath' => 'uploads/avatar',
];
$this->config = ArrayHelper::merge($config, $this->config);
parent::init();
}
public function run()
{
$model = new UploadForm();
if (Yii::$app->request->isPost) {
$model->imageFile = UploadedFile::getInstance($model, 'imageFile');
$post = Yii::$app->request->post();
$model->avatarData = $post['UploadForm']['avatarData'];
$model->config = $this->config;
if ($model->upload()) {
// 文件上传成功
return json_encode(['state'=>200,'message'=>'上传成功!','result'=>$model->imageUrl]);
}
}
}
}