Commit 159f29c24ef7d6ec0618bc1dbdd7777a5285d663
1 parent
04b510ec
Importers CRUD
Showing
3 changed files
with
11 additions
and
7 deletions
Show diff stats
backend/components/base/BaseController.php
@@ -45,11 +45,9 @@ class BaseController extends Controller { | @@ -45,11 +45,9 @@ class BaseController extends Controller { | ||
45 | 45 | ||
46 | 46 | ||
47 | } | 47 | } |
48 | - | 48 | +// |
49 | // private function resizeImg($w, $h, $filepath,$newfilepath){ | 49 | // private function resizeImg($w, $h, $filepath,$newfilepath){ |
50 | -// list($orig_width, $orig_height) = getimagesize($filepath); | ||
51 | -// $width = $orig_width; | ||
52 | -// $height = $orig_height; | 50 | +// list($width, $height) = getimagesize($filepath); |
53 | // if($width > $height) { | 51 | // if($width > $height) { |
54 | // $y = 0; | 52 | // $y = 0; |
55 | // $x = ($width - $height) / 2; | 53 | // $x = ($width - $height) / 2; |
@@ -76,7 +74,7 @@ class BaseController extends Controller { | @@ -76,7 +74,7 @@ class BaseController extends Controller { | ||
76 | { | 74 | { |
77 | 75 | ||
78 | $model = new ImageSizerForm(); | 76 | $model = new ImageSizerForm(); |
79 | - //die(print_r(Yii::$app->request->post())); | 77 | + |
80 | if ($model->load(Yii::$app->request->post())) { | 78 | if ($model->load(Yii::$app->request->post())) { |
81 | 79 | ||
82 | $model->file = UploadedFile::getInstance($model, 'file'); | 80 | $model->file = UploadedFile::getInstance($model, 'file'); |
@@ -85,6 +83,7 @@ class BaseController extends Controller { | @@ -85,6 +83,7 @@ class BaseController extends Controller { | ||
85 | $imgDir = Yii::getAlias('@storage/'.$md5_file.'/'); | 83 | $imgDir = Yii::getAlias('@storage/'.$md5_file.'/'); |
86 | $imageAlias = Yii::getAlias($imgDir.$model->width.'x'.$model->height.'.'.$model->file->extension); | 84 | $imageAlias = Yii::getAlias($imgDir.$model->width.'x'.$model->height.'.'.$model->file->extension); |
87 | $imageLink = '/storage/'.$md5_file.$model->width.'x'.$model->height.'.'.$model->file->extension; | 85 | $imageLink = '/storage/'.$md5_file.$model->width.'x'.$model->height.'.'.$model->file->extension; |
86 | + | ||
88 | if(!is_dir($imgDir)) { | 87 | if(!is_dir($imgDir)) { |
89 | mkdir($imgDir, 0755, true); | 88 | mkdir($imgDir, 0755, true); |
90 | } | 89 | } |
backend/components/views/image_sizer.php
@@ -12,7 +12,7 @@ $this->registerJsFile('@web/js/vendor/bower/jquery-file-upload/js/jquery.fileupl | @@ -12,7 +12,7 @@ $this->registerJsFile('@web/js/vendor/bower/jquery-file-upload/js/jquery.fileupl | ||
12 | 12 | ||
13 | ?> | 13 | ?> |
14 | 14 | ||
15 | -<?= $form->field($model, 'file')->fileInput(['id'=>$field, 'data-url'=>"/admin/site/download-photo"]); ?> | 15 | +<?= $form->field( new \backend\models\ImageSizerForm(), 'file')->fileInput(['id'=>$field, 'data-url'=>"/admin/site/download-photo"]); ?> |
16 | 16 | ||
17 | <?= $form->field($model,$field)->hiddenInput(['id' => "{$field}_picture_link"]) ?> | 17 | <?= $form->field($model,$field)->hiddenInput(['id' => "{$field}_picture_link"]) ?> |
18 | 18 | ||
@@ -25,7 +25,7 @@ $this->registerJsFile('@web/js/vendor/bower/jquery-file-upload/js/jquery.fileupl | @@ -25,7 +25,7 @@ $this->registerJsFile('@web/js/vendor/bower/jquery-file-upload/js/jquery.fileupl | ||
25 | 25 | ||
26 | $("#<?= $field?>").fileupload({ | 26 | $("#<?= $field?>").fileupload({ |
27 | dataType: 'json', | 27 | dataType: 'json', |
28 | - formData: { | 28 | + ImageSizerForm: { |
29 | height: <?=$height?>, | 29 | height: <?=$height?>, |
30 | width: <?= $width?> | 30 | width: <?= $width?> |
31 | }, | 31 | }, |
backend/models/ImageSizerForm.php
@@ -13,6 +13,11 @@ class ImageSizerForm extends Model | @@ -13,6 +13,11 @@ class ImageSizerForm extends Model | ||
13 | * @var UploadedFile file attribute | 13 | * @var UploadedFile file attribute |
14 | */ | 14 | */ |
15 | public $file; | 15 | public $file; |
16 | + public $width; | ||
17 | + public $height; | ||
18 | + public $field; | ||
19 | + public $model; | ||
20 | + public $form; | ||
16 | 21 | ||
17 | /** | 22 | /** |
18 | * @return array the validation rules. | 23 | * @return array the validation rules. |