Commit 143c55a9e4858fe8a639e66353b72110b33a2ae5
1 parent
e10587b1
Namespaces
Showing
6 changed files
with
420 additions
and
384 deletions
Show diff stats
FileUploadAsset.php
1 | <?php | 1 | <?php |
2 | -/** | ||
3 | - * @link http://www.yiiframework.com/ | ||
4 | - * @copyright Copyright (c) 2008 Yii Software LLC | ||
5 | - * @license http://www.yiiframework.com/license/ | ||
6 | - */ | ||
7 | - | ||
8 | - | ||
9 | -namespace artweb\artbox\file; | ||
10 | - | ||
11 | -use yii\helpers\Url; | ||
12 | -use yii\web\AssetBundle; | ||
13 | - | ||
14 | -/** | ||
15 | - * Asset bundle for the Twitter bootstrap javascript files. | ||
16 | - * | ||
17 | - * @author Qiang Xue <qiang.xue@gmail.com> | ||
18 | - * @since 2.0 | ||
19 | - */ | ||
20 | -class FileUploadAsset extends AssetBundle | ||
21 | -{ | ||
22 | - | ||
23 | - | ||
24 | /** | 2 | /** |
25 | - * @inheritdoc | 3 | + * @link http://www.yiiframework.com/ |
4 | + * @copyright Copyright (c) 2008 Yii Software LLC | ||
5 | + * @license http://www.yiiframework.com/license/ | ||
26 | */ | 6 | */ |
27 | - public function init() | 7 | + |
8 | + namespace artweb\artbox\file; | ||
9 | + | ||
10 | + use yii\web\AssetBundle; | ||
11 | + | ||
12 | + /** | ||
13 | + * Asset bundle for the Twitter bootstrap javascript files. | ||
14 | + * | ||
15 | + * @author Qiang Xue <qiang.xue@gmail.com> | ||
16 | + * @since 2.0 | ||
17 | + */ | ||
18 | + class FileUploadAsset extends AssetBundle | ||
28 | { | 19 | { |
29 | - parent::init(); | ||
30 | - $this->sourcePath = __DIR__.'/assets'; | 20 | + |
21 | + /** | ||
22 | + * @inheritdoc | ||
23 | + */ | ||
24 | + public function init() | ||
25 | + { | ||
26 | + parent::init(); | ||
27 | + $this->sourcePath = __DIR__ . '/assets'; | ||
28 | + } | ||
29 | + | ||
30 | + public $css = [ | ||
31 | + 'css/jquery.fileupload.css', | ||
32 | + 'css/fileupload/style.css', | ||
33 | + ]; | ||
34 | + | ||
35 | + public $js = [ | ||
36 | + 'js/vendor/jquery.ui.widget.js', | ||
37 | + 'js/jquery.iframe-transport.js', | ||
38 | + 'js/jquery.fileupload.js', | ||
39 | + ]; | ||
31 | } | 40 | } |
32 | - | ||
33 | - public $css = [ | ||
34 | - 'css/jquery.fileupload.css', | ||
35 | - 'css/fileupload/style.css' | ||
36 | - ]; | ||
37 | - | ||
38 | - public $js = [ | ||
39 | - 'js/vendor/jquery.ui.widget.js', | ||
40 | - 'js/jquery.iframe-transport.js', | ||
41 | - 'js/jquery.fileupload.js' | ||
42 | - ]; | ||
43 | -} |
Module.php
1 | <?php | 1 | <?php |
2 | -namespace artweb\artbox\file; | ||
3 | - | ||
4 | -use yii\base\BootstrapInterface; | ||
5 | - | ||
6 | -class Module extends \yii\base\Module | ||
7 | -{ | ||
8 | - public function init() | ||
9 | - { | ||
10 | - parent::init(); | ||
11 | - | ||
12 | - \Yii::configure($this, require(__DIR__.'/config.php')); | ||
13 | - } | ||
14 | - | ||
15 | -} | 2 | + namespace artweb\artbox\file; |
3 | + | ||
4 | + class Module extends \yii\base\Module | ||
5 | + { | ||
6 | + public function init() | ||
7 | + { | ||
8 | + parent::init(); | ||
9 | + | ||
10 | + \Yii::configure($this, require( __DIR__ . '/config.php' )); | ||
11 | + } | ||
12 | + | ||
13 | + } |
composer.json
@@ -5,7 +5,9 @@ | @@ -5,7 +5,9 @@ | ||
5 | "require": { | 5 | "require": { |
6 | "php": ">=7.0", | 6 | "php": ">=7.0", |
7 | "yiisoft/yii2": "*", | 7 | "yiisoft/yii2": "*", |
8 | - "developeruz/yii2-db-rbac": "*" | 8 | + "developeruz/yii2-db-rbac": "*", |
9 | + "artweb/artbox": "dev-master", | ||
10 | + "artweb/artbox/language": "dev-master" | ||
9 | }, | 11 | }, |
10 | "autoload": { | 12 | "autoload": { |
11 | "psr-4": { | 13 | "psr-4": { |
controllers/UploaderController.php
1 | <?php | 1 | <?php |
2 | -/** | ||
3 | - * Created by PhpStorm. | ||
4 | - * User: Cibermag | ||
5 | - * Date: 31.08.2015 | ||
6 | - * Time: 9:58 | ||
7 | - */ | ||
8 | -namespace artweb\artbox\file\controllers; | ||
9 | -use Yii; | ||
10 | -use yii\helpers\ArrayHelper; | ||
11 | -use yii\web\UploadedFile; | ||
12 | -use artweb\artbox\file\models\ImageSizerForm; | ||
13 | -use yii\web\Controller; | ||
14 | -use Imagine\Gd\Imagine; | ||
15 | -use Imagine\Image\Box; | ||
16 | -use yii\imagine\Image; | ||
17 | - | ||
18 | -class UploaderController extends Controller { | ||
19 | - | ||
20 | - public $enableCsrfValidation = false; | ||
21 | - | ||
22 | - public function isBigger($width,$height,$w,$h) | 2 | + /** |
3 | + * Created by PhpStorm. | ||
4 | + * User: Cibermag | ||
5 | + * Date: 31.08.2015 | ||
6 | + * Time: 9:58 | ||
7 | + */ | ||
8 | + namespace artweb\artbox\file\controllers; | ||
9 | + | ||
10 | + use Yii; | ||
11 | + use yii\helpers\ArrayHelper; | ||
12 | + use yii\web\UploadedFile; | ||
13 | + use artweb\artbox\file\models\ImageSizerForm; | ||
14 | + use yii\web\Controller; | ||
15 | + use Imagine\Gd\Imagine; | ||
16 | + use Imagine\Image\Box; | ||
17 | + use yii\imagine\Image; | ||
18 | + | ||
19 | + class UploaderController extends Controller | ||
23 | { | 20 | { |
24 | - if($width>$w){ | ||
25 | - return true; | ||
26 | - }else if($height >$h) { | ||
27 | - return true; | 21 | + |
22 | + public $enableCsrfValidation = false; | ||
23 | + | ||
24 | + public function isBigger($width, $height, $w, $h) | ||
25 | + { | ||
26 | + if ($width > $w) { | ||
27 | + return true; | ||
28 | + } else if ($height > $h) { | ||
29 | + return true; | ||
30 | + } | ||
31 | + return false; | ||
28 | } | 32 | } |
29 | - return false; | ||
30 | - } | ||
31 | - | ||
32 | - | ||
33 | - private function getUserPath(){ | ||
34 | - if(isset(Yii::$app->user->id)){ | ||
35 | - return 'user_'.Yii::$app->user->id; | ||
36 | - }else { | ||
37 | - return 'guest'; | 33 | + |
34 | + private function getUserPath() | ||
35 | + { | ||
36 | + if (isset( Yii::$app->user->id )) { | ||
37 | + return 'user_' . Yii::$app->user->id; | ||
38 | + } else { | ||
39 | + return 'guest'; | ||
40 | + } | ||
38 | } | 41 | } |
39 | - } | ||
40 | - | ||
41 | - private function resizeImg($w, $h, $imageAlias,$imageAliasSave){ | ||
42 | - $img = Image::getImagine()->open(Yii::getAlias($imageAlias)); | ||
43 | - | ||
44 | - $size = $img->getSize(); | ||
45 | - | ||
46 | - $width = $size->getWidth(); | ||
47 | - $height = $size->getHeight(); | ||
48 | - | ||
49 | - $e_width = $w/$h; | ||
50 | - $e_height = $h/$w; | ||
51 | - | ||
52 | - $e1_width = $width/$height; | ||
53 | - $e1_height = $height/$width; | ||
54 | - | ||
55 | - | ||
56 | - | ||
57 | - if($e_width<$e1_width){ | ||
58 | - | ||
59 | - $new_width = $width*($e_width/$e1_width); | ||
60 | - | 42 | + |
43 | + private function resizeImg($w, $h, $imageAlias, $imageAliasSave) | ||
44 | + { | ||
45 | + $img = Image::getImagine() | ||
46 | + ->open(Yii::getAlias($imageAlias)); | ||
47 | + | ||
48 | + $size = $img->getSize(); | ||
49 | + | ||
50 | + $width = $size->getWidth(); | ||
51 | + $height = $size->getHeight(); | ||
52 | + | ||
53 | + $e_width = $w / $h; | ||
54 | + $e_height = $h / $w; | ||
55 | + | ||
56 | + $e1_width = $width / $height; | ||
57 | + $e1_height = $height / $width; | ||
58 | + | ||
59 | + if ($e_width < $e1_width) { | ||
60 | + | ||
61 | + $new_width = $width * ( $e_width / $e1_width ); | ||
62 | + | ||
61 | $y = 0; | 63 | $y = 0; |
62 | - $x = $width/ 2-($new_width/2); | 64 | + $x = $width / 2 - ( $new_width / 2 ); |
63 | $width = $new_width; | 65 | $width = $new_width; |
64 | - | ||
65 | - }else { | ||
66 | - | ||
67 | - $new_height = $height*($e_height/$e1_height); | 66 | + |
67 | + } else { | ||
68 | + | ||
69 | + $new_height = $height * ( $e_height / $e1_height ); | ||
68 | $x = 0; | 70 | $x = 0; |
69 | - $y = $height/2-($new_height/2); | 71 | + $y = $height / 2 - ( $new_height / 2 ); |
70 | $height = $new_height; | 72 | $height = $new_height; |
71 | } | 73 | } |
72 | - | ||
73 | - | ||
74 | - | ||
75 | - | ||
76 | - Image::crop($imageAlias, $width, $height,[$x,$y]) | ||
77 | - ->save(Yii::getAlias($imageAliasSave), ['quality' => | ||
78 | - 100]); | ||
79 | - | ||
80 | - | ||
81 | - $imagine = new Imagine(); | ||
82 | - $imagine->open($imageAliasSave) | ||
83 | - ->resize(new Box($w, $h)) | ||
84 | - ->save($imageAliasSave, array('flatten' => false)); | ||
85 | - | ||
86 | - | ||
87 | - | ||
88 | - } | ||
89 | - | ||
90 | - private function deleteImages($old_img){ | ||
91 | - | ||
92 | - if(!empty($old_img) && file_exists($_SERVER['DOCUMENT_ROOT'].$old_img)){ | ||
93 | - | ||
94 | - $rootDir = explode("/", $old_img); | ||
95 | - | ||
96 | - $row = $_SERVER['DOCUMENT_ROOT'].'/'.$rootDir[1].'/'.$rootDir[2].'/'.$rootDir[3].'/'; | ||
97 | - | ||
98 | - $allFiles = scandir($row); | ||
99 | - | ||
100 | - $allFiles = array_slice($allFiles, 2); | ||
101 | - | ||
102 | - foreach($allFiles as $oldFile){ | ||
103 | - | ||
104 | - unlink($row.$oldFile); | ||
105 | - | ||
106 | - } | ||
107 | - | 74 | + |
75 | + Image::crop( | ||
76 | + $imageAlias, | ||
77 | + $width, | ||
78 | + $height, | ||
79 | + [ | ||
80 | + $x, | ||
81 | + $y, | ||
82 | + ] | ||
83 | + ) | ||
84 | + ->save( | ||
85 | + Yii::getAlias($imageAliasSave), | ||
86 | + [ | ||
87 | + 'quality' => 100, | ||
88 | + ] | ||
89 | + ); | ||
90 | + | ||
91 | + $imagine = new Imagine(); | ||
92 | + $imagine->open($imageAliasSave) | ||
93 | + ->resize(new Box($w, $h)) | ||
94 | + ->save($imageAliasSave, [ 'flatten' => false ]); | ||
95 | + | ||
108 | } | 96 | } |
109 | - } | ||
110 | - | ||
111 | - public function actionDeleteImage(){ | ||
112 | - | ||
113 | - $this->enableCsrfValidation = false; | ||
114 | - | ||
115 | - $request = Yii::$app->request->post(); | ||
116 | - | ||
117 | - if($request){ | ||
118 | - if ($request['old_img']) { | ||
119 | - $this->deleteImages($request['old_img']); | ||
120 | - } | ||
121 | - if(isset($request['action']) && $request['action']=='save'){ | ||
122 | - $object = str_replace('-', '\\',$request['model']); | ||
123 | - $model = new $object; | ||
124 | - $model = $model->findOne($request['id']); | ||
125 | - $model->$request['field'] = $request['new_url']; | ||
126 | - $model->save(); | 97 | + |
98 | + private function deleteImages($old_img) | ||
99 | + { | ||
100 | + | ||
101 | + if (!empty( $old_img ) && file_exists($_SERVER[ 'DOCUMENT_ROOT' ] . $old_img)) { | ||
102 | + | ||
103 | + $rootDir = explode("/", $old_img); | ||
104 | + | ||
105 | + $row = $_SERVER[ 'DOCUMENT_ROOT' ] . '/' . $rootDir[ 1 ] . '/' . $rootDir[ 2 ] . '/' . $rootDir[ 3 ] . '/'; | ||
106 | + | ||
107 | + $allFiles = scandir($row); | ||
108 | + | ||
109 | + $allFiles = array_slice($allFiles, 2); | ||
110 | + | ||
111 | + foreach ($allFiles as $oldFile) { | ||
112 | + | ||
113 | + unlink($row . $oldFile); | ||
114 | + | ||
115 | + } | ||
116 | + | ||
127 | } | 117 | } |
128 | } | 118 | } |
129 | - | ||
130 | - } | ||
131 | - | ||
132 | - | ||
133 | - public function actionDownloadPhoto() | ||
134 | - { | ||
135 | - | ||
136 | - $model = new ImageSizerForm(); | ||
137 | - | ||
138 | - $request = Yii::$app->request->post(); | ||
139 | - | ||
140 | - if ($request) { | ||
141 | - | ||
142 | - $model->multi = isset($request['multi'])? 1 : 0; | ||
143 | - | ||
144 | - $model->file = UploadedFile::getInstance($model, 'file'); | ||
145 | - | ||
146 | - $md5_file = md5_file($model->file->tempName).rand(1, 1000); | ||
147 | - | ||
148 | - $imgDir = Yii::getAlias('@storage/'.$this->getUserPath().'/'.$md5_file.'/'); | ||
149 | - | ||
150 | - $imageOrigAlias = Yii::getAlias($imgDir.'original'.'.'.$model->file->extension); | ||
151 | - | ||
152 | - if(!is_dir($imgDir)) { | ||
153 | - mkdir($imgDir, 0755, true); | 119 | + |
120 | + public function actionDeleteImage() | ||
121 | + { | ||
122 | + | ||
123 | + $this->enableCsrfValidation = false; | ||
124 | + | ||
125 | + $request = Yii::$app->request->post(); | ||
126 | + | ||
127 | + if ($request) { | ||
128 | + if ($request[ 'old_img' ]) { | ||
129 | + $this->deleteImages($request[ 'old_img' ]); | ||
130 | + } | ||
131 | + if (isset( $request[ 'action' ] ) && $request[ 'action' ] == 'save') { | ||
132 | + $object = str_replace('-', '\\', $request[ 'model' ]); | ||
133 | + $model = new $object; | ||
134 | + $model = $model->findOne($request[ 'id' ]); | ||
135 | + $model->$request[ 'field' ] = $request[ 'new_url' ]; | ||
136 | + $model->save(); | ||
137 | + } | ||
154 | } | 138 | } |
155 | - | ||
156 | - $model->file->saveAs($imageOrigAlias); | ||
157 | - | ||
158 | - | ||
159 | - if(isset($request['size'] )){ | ||
160 | - | ||
161 | - $request['size'] = ArrayHelper::toArray(json_decode($request['size'])); | ||
162 | - | ||
163 | - foreach($request['size'] as $size){ | ||
164 | - if($size['width'] && $size['height']){ | ||
165 | - | ||
166 | - $imageAlias = Yii::getAlias($imgDir.$size['width'].'x'.$size['height'].'.'.$model->file->extension); | ||
167 | - | ||
168 | - $imageLink = '/storage/'.$this->getUserPath().'/'.$md5_file.'/'.$size['width'].'x'.$size['height'].'.'.$model->file->extension; | ||
169 | - | ||
170 | - $this->resizeImg($size['width'], $size['height'], $imageOrigAlias,$imageAlias); | ||
171 | - | 139 | + |
140 | + } | ||
141 | + | ||
142 | + public function actionDownloadPhoto() | ||
143 | + { | ||
144 | + | ||
145 | + $model = new ImageSizerForm(); | ||
146 | + | ||
147 | + $request = Yii::$app->request->post(); | ||
148 | + | ||
149 | + if ($request) { | ||
150 | + | ||
151 | + $model->multi = isset( $request[ 'multi' ] ) ? 1 : 0; | ||
152 | + | ||
153 | + $model->file = UploadedFile::getInstance($model, 'file'); | ||
154 | + | ||
155 | + $md5_file = md5_file($model->file->tempName) . rand(1, 1000); | ||
156 | + | ||
157 | + $imgDir = Yii::getAlias('@storage/' . $this->getUserPath() . '/' . $md5_file . '/'); | ||
158 | + | ||
159 | + $imageOrigAlias = Yii::getAlias($imgDir . 'original' . '.' . $model->file->extension); | ||
160 | + | ||
161 | + if (!is_dir($imgDir)) { | ||
162 | + mkdir($imgDir, 0755, true); | ||
163 | + } | ||
164 | + | ||
165 | + $model->file->saveAs($imageOrigAlias); | ||
166 | + | ||
167 | + if (isset( $request[ 'size' ] )) { | ||
168 | + | ||
169 | + $request[ 'size' ] = ArrayHelper::toArray(json_decode($request[ 'size' ])); | ||
170 | + | ||
171 | + foreach ($request[ 'size' ] as $size) { | ||
172 | + if ($size[ 'width' ] && $size[ 'height' ]) { | ||
173 | + | ||
174 | + $imageAlias = Yii::getAlias( | ||
175 | + $imgDir . $size[ 'width' ] . 'x' . $size[ 'height' ] . '.' . $model->file->extension | ||
176 | + ); | ||
177 | + | ||
178 | + $imageLink = '/storage/' . $this->getUserPath( | ||
179 | + ) . '/' . $md5_file . '/' . $size[ 'width' ] . 'x' . $size[ 'height' ] . '.' . $model->file->extension; | ||
180 | + | ||
181 | + $this->resizeImg($size[ 'width' ], $size[ 'height' ], $imageOrigAlias, $imageAlias); | ||
182 | + | ||
183 | + } | ||
172 | } | 184 | } |
185 | + | ||
186 | + } else { | ||
187 | + | ||
188 | + $imageLink = '/storage/' . $this->getUserPath( | ||
189 | + ) . '/' . $md5_file . '/' . 'original' . '.' . $model->file->extension; | ||
190 | + | ||
173 | } | 191 | } |
174 | - | ||
175 | - } else { | ||
176 | - | ||
177 | - $imageLink = '/storage/'.$this->getUserPath().'/'.$md5_file.'/'.'original'.'.'.$model->file->extension; | ||
178 | - | ||
179 | - } | ||
180 | - | ||
181 | - | ||
182 | - if($model->multi){ | ||
183 | - $view = $this->renderPartial('/_gallery_item', [ | ||
184 | - 'item' => ['image'=>$imageLink], | ||
185 | - 'field'=>$request['field'] | ||
186 | - ]); | ||
187 | - return json_encode(['link'=>$imageLink, | ||
188 | - 'view' =>$view, | ||
189 | - | ||
190 | - ]); | ||
191 | - | ||
192 | - | ||
193 | - } else { | ||
194 | - $view = $this->renderPartial('/_one_item', [ | ||
195 | - 'item' => ['image'=>$imageLink], | ||
196 | - 'field'=>$request['field'] | ||
197 | - ]); | ||
198 | - return json_encode(['link'=>$imageLink, | ||
199 | - 'view' =>$view, | ||
200 | - ]); | 192 | + |
193 | + if ($model->multi) { | ||
194 | + $view = $this->renderPartial( | ||
195 | + '/_gallery_item', | ||
196 | + [ | ||
197 | + 'item' => [ 'image' => $imageLink ], | ||
198 | + 'field' => $request[ 'field' ], | ||
199 | + ] | ||
200 | + ); | ||
201 | + return json_encode( | ||
202 | + [ | ||
203 | + 'link' => $imageLink, | ||
204 | + 'view' => $view, | ||
205 | + | ||
206 | + ] | ||
207 | + ); | ||
208 | + | ||
209 | + } else { | ||
210 | + $view = $this->renderPartial( | ||
211 | + '/_one_item', | ||
212 | + [ | ||
213 | + 'item' => [ 'image' => $imageLink ], | ||
214 | + 'field' => $request[ 'field' ], | ||
215 | + ] | ||
216 | + ); | ||
217 | + return json_encode( | ||
218 | + [ | ||
219 | + 'link' => $imageLink, | ||
220 | + 'view' => $view, | ||
221 | + ] | ||
222 | + ); | ||
223 | + } | ||
224 | + | ||
201 | } | 225 | } |
202 | - | ||
203 | - | ||
204 | } | 226 | } |
205 | - } | ||
206 | - | ||
207 | - | ||
208 | - public function getex($filename) { | ||
209 | - $array = explode(".", $filename); | ||
210 | - return array_pop($array); | ||
211 | - } | ||
212 | - | ||
213 | - | ||
214 | - public function actionImagesUpload(){ | ||
215 | - | ||
216 | - if($_FILES['upload']) | 227 | + |
228 | + public function getex($filename) | ||
217 | { | 229 | { |
218 | - if (($_FILES['upload'] == "none") OR (empty($_FILES['upload']['name'])) ) | ||
219 | - { | ||
220 | - $message = "ะั ะฝะต ะฒัะฑัะฐะปะธ ัะฐะนะป"; | ||
221 | - } | ||
222 | - else if ($_FILES['upload']["size"] == 0 OR $_FILES['upload']["size"] > 2050000) | ||
223 | - { | ||
224 | - $message = "ะ ะฐะทะผะตั ัะฐะนะปะฐ ะฝะต ัะพะพัะฒะตัััะฒัะตั ะฝะพัะผะฐะผ"; | ||
225 | - } | ||
226 | - else if (($_FILES['upload']["type"] != "image/jpeg") AND ($_FILES['upload']["type"] != "image/jpeg") AND ($_FILES['upload']["type"] != "image/png") AND ($_FILES['upload']['type'] != 'image/gif')) | ||
227 | - { | ||
228 | - $message = "ะะพะฟััะบะฐะตััั ะทะฐะณััะทะบะฐ ัะพะปัะบะพ ะบะฐััะธะฝะพะบ JPG ะธ PNG."; | ||
229 | - } | ||
230 | - else if (!is_uploaded_file($_FILES['upload']["tmp_name"])) | ||
231 | - { | ||
232 | - $message = "ะงัะพ-ัะพ ะฟะพัะปะพ ะฝะต ัะฐะบ. ะะพะฟััะฐะนัะตัั ะทะฐะณััะทะธัั ัะฐะนะป ะตัั ัะฐะท."; | ||
233 | - } | ||
234 | - else{ | ||
235 | - $filename = $_FILES['upload']['name']; | ||
236 | - $name =$_FILES['upload']['name'].'.'.$this->getex($filename); | ||
237 | - | ||
238 | - $path = "../../storage/".$this->getUserPath()."/images/"; | ||
239 | - if(!is_dir($path)) { | ||
240 | - mkdir($path, 0755, true); | 230 | + $array = explode(".", $filename); |
231 | + return array_pop($array); | ||
232 | + } | ||
233 | + | ||
234 | + public function actionImagesUpload() | ||
235 | + { | ||
236 | + | ||
237 | + if ($_FILES[ 'upload' ]) { | ||
238 | + if (( $_FILES[ 'upload' ] == "none" ) OR ( empty( $_FILES[ 'upload' ][ 'name' ] ) )) { | ||
239 | + $message = "ะั ะฝะต ะฒัะฑัะฐะปะธ ัะฐะนะป"; | ||
240 | + } else if ($_FILES[ 'upload' ][ "size" ] == 0 OR $_FILES[ 'upload' ][ "size" ] > 2050000) { | ||
241 | + $message = "ะ ะฐะทะผะตั ัะฐะนะปะฐ ะฝะต ัะพะพัะฒะตัััะฒัะตั ะฝะพัะผะฐะผ"; | ||
242 | + } else if (( $_FILES[ 'upload' ][ "type" ] != "image/jpeg" ) AND ( $_FILES[ 'upload' ][ "type" ] != "image/jpeg" ) AND ( $_FILES[ 'upload' ][ "type" ] != "image/png" ) AND ( $_FILES[ 'upload' ][ 'type' ] != 'image/gif' )) { | ||
243 | + $message = "ะะพะฟััะบะฐะตััั ะทะฐะณััะทะบะฐ ัะพะปัะบะพ ะบะฐััะธะฝะพะบ JPG ะธ PNG."; | ||
244 | + } else if (!is_uploaded_file($_FILES[ 'upload' ][ "tmp_name" ])) { | ||
245 | + $message = "ะงัะพ-ัะพ ะฟะพัะปะพ ะฝะต ัะฐะบ. ะะพะฟััะฐะนัะตัั ะทะฐะณััะทะธัั ัะฐะนะป ะตัั ัะฐะท."; | ||
246 | + } else { | ||
247 | + $filename = $_FILES[ 'upload' ][ 'name' ]; | ||
248 | + $name = $_FILES[ 'upload' ][ 'name' ] . '.' . $this->getex($filename); | ||
249 | + | ||
250 | + $path = "../../storage/" . $this->getUserPath() . "/images/"; | ||
251 | + if (!is_dir($path)) { | ||
252 | + mkdir($path, 0755, true); | ||
253 | + } | ||
254 | + | ||
255 | + move_uploaded_file($_FILES[ 'upload' ][ 'tmp_name' ], $path . $name); | ||
256 | + | ||
257 | + $full_path = '/storage/' . $this->getUserPath() . '/images/' . $name; | ||
258 | + | ||
259 | + $message = "ะคะฐะนะป " . $_FILES[ 'upload' ][ 'name' ] . " ะทะฐะณััะถะตะฝ"; | ||
260 | + | ||
241 | } | 261 | } |
242 | - | ||
243 | - | ||
244 | - | ||
245 | - move_uploaded_file($_FILES['upload']['tmp_name'], $path.$name); | ||
246 | - | ||
247 | - $full_path = '/storage/'.$this->getUserPath().'/images/'.$name; | ||
248 | - | ||
249 | - $message = "ะคะฐะนะป ".$_FILES['upload']['name']." ะทะฐะณััะถะตะฝ"; | ||
250 | - | ||
251 | - | 262 | + $callback = $_REQUEST[ 'CKEditorFuncNum' ]; |
263 | + echo '<script type="text/javascript">window.parent.CKEDITOR.tools.callFunction("' . $callback . '", "' . $full_path . '", "' . $message . '" );</script>'; | ||
252 | } | 264 | } |
253 | - $callback = $_REQUEST['CKEditorFuncNum']; | ||
254 | - echo '<script type="text/javascript">window.parent.CKEDITOR.tools.callFunction("'.$callback.'", "'.$full_path.'", "'.$message.'" );</script>'; | ||
255 | } | 265 | } |
256 | - } | ||
257 | - | ||
258 | - | ||
259 | -} | ||
260 | \ No newline at end of file | 266 | \ No newline at end of file |
267 | + | ||
268 | + } | ||
261 | \ No newline at end of file | 269 | \ No newline at end of file |
models/ImageSizerForm.php
1 | <?php | 1 | <?php |
2 | -namespace artweb\artbox\file\models; | ||
3 | - | ||
4 | -use yii\base\Model; | ||
5 | -use yii\web\UploadedFile; | ||
6 | - | ||
7 | -/** | ||
8 | - * UploadForm is the model behind the upload form. | ||
9 | - */ | ||
10 | -class ImageSizerForm extends Model | ||
11 | -{ | 2 | + namespace artweb\artbox\file\models; |
3 | + | ||
4 | + use yii\base\Model; | ||
5 | + use yii\web\UploadedFile; | ||
6 | + | ||
12 | /** | 7 | /** |
13 | - * @var UploadedFile file attribute | 8 | + * UploadForm is the model behind the upload form. |
14 | */ | 9 | */ |
15 | - public $file; | ||
16 | - public $width; | ||
17 | - public $height; | ||
18 | - public $field; | ||
19 | - public $model; | ||
20 | - public $form; | ||
21 | - public $multi; | ||
22 | - public $old_img; | ||
23 | - public $img; | ||
24 | - public $price_list; | ||
25 | - | ||
26 | - /** | ||
27 | - * @return array the validation rules. | ||
28 | - */ | ||
29 | - public function rules() | 10 | + class ImageSizerForm extends Model |
30 | { | 11 | { |
31 | - return [ | ||
32 | - [['width', 'height', 'multi'], 'integer'], | ||
33 | - [['field', 'multi','old_img'], 'string', 'max' => 255], | ||
34 | - [['model', 'form',], 'string'], | ||
35 | - [['file','img','price_list'], 'file'], | ||
36 | - ]; | ||
37 | - } | ||
38 | -} | ||
39 | \ No newline at end of file | 12 | \ No newline at end of file |
13 | + /** | ||
14 | + * @var UploadedFile file attribute | ||
15 | + */ | ||
16 | + public $file; | ||
17 | + public $width; | ||
18 | + public $height; | ||
19 | + public $field; | ||
20 | + public $model; | ||
21 | + public $form; | ||
22 | + public $multi; | ||
23 | + public $old_img; | ||
24 | + public $img; | ||
25 | + public $price_list; | ||
26 | + | ||
27 | + /** | ||
28 | + * @return array the validation rules. | ||
29 | + */ | ||
30 | + public function rules() | ||
31 | + { | ||
32 | + return [ | ||
33 | + [ | ||
34 | + [ | ||
35 | + 'width', | ||
36 | + 'height', | ||
37 | + 'multi', | ||
38 | + ], | ||
39 | + 'integer', | ||
40 | + ], | ||
41 | + [ | ||
42 | + [ | ||
43 | + 'field', | ||
44 | + 'multi', | ||
45 | + 'old_img', | ||
46 | + ], | ||
47 | + 'string', | ||
48 | + 'max' => 255, | ||
49 | + ], | ||
50 | + [ | ||
51 | + [ | ||
52 | + 'model', | ||
53 | + 'form', | ||
54 | + ], | ||
55 | + 'string', | ||
56 | + ], | ||
57 | + [ | ||
58 | + [ | ||
59 | + 'file', | ||
60 | + 'img', | ||
61 | + 'price_list', | ||
62 | + ], | ||
63 | + 'file', | ||
64 | + ], | ||
65 | + ]; | ||
66 | + } | ||
67 | + } | ||
40 | \ No newline at end of file | 68 | \ No newline at end of file |
widgets/ImageUploader.php
1 | <?php | 1 | <?php |
2 | -/** | ||
3 | - * Created by PhpStorm. | ||
4 | - * User: vitaliy | ||
5 | - * Date: 05.10.15 | ||
6 | - * Time: 16:18 | ||
7 | - */ | ||
8 | - | ||
9 | -namespace artweb\artbox\file\widgets; | ||
10 | -use yii\base\Widget; | ||
11 | - | ||
12 | - | ||
13 | -class ImageUploader extends Widget | ||
14 | -{ | ||
15 | - public $height = 0; | ||
16 | - public $width = 0; | ||
17 | - public $field; | ||
18 | - public $file; | ||
19 | - public $model; | ||
20 | - public $multi = false; | ||
21 | - public $gallery; | ||
22 | - public $size; | ||
23 | - public $name = 'Add file...'; | ||
24 | - public $remover = 0; | ||
25 | - | ||
26 | - public function init(){ | ||
27 | - | ||
28 | - parent::init(); | ||
29 | - | ||
30 | - } | ||
31 | - | ||
32 | - | ||
33 | - public function run() | 2 | + /** |
3 | + * Created by PhpStorm. | ||
4 | + * User: vitaliy | ||
5 | + * Date: 05.10.15 | ||
6 | + * Time: 16:18 | ||
7 | + */ | ||
8 | + | ||
9 | + namespace artweb\artbox\file\widgets; | ||
10 | + | ||
11 | + use yii\base\Widget; | ||
12 | + | ||
13 | + class ImageUploader extends Widget | ||
34 | { | 14 | { |
35 | - | ||
36 | - return $this->render('image_sizer', | ||
37 | - [ | ||
38 | - 'model'=>$this->model, | ||
39 | - 'size' => $this->size, | ||
40 | - 'field' => $this->field, | ||
41 | - 'height' => $this->height, | ||
42 | - 'width' => $this->width, | ||
43 | - 'multi' => $this->multi, | ||
44 | - 'name' => $this->name, | ||
45 | - 'remover' => $this->remover | ||
46 | - ]); | ||
47 | - | ||
48 | - } | ||
49 | - | ||
50 | - public function getGallery(){ | ||
51 | - if($this->gallery){ | ||
52 | - $array = explode(",", $this->gallery); | ||
53 | - if(count($array) > 1){ | ||
54 | - array_pop($array); | 15 | + public $height = 0; |
16 | + public $width = 0; | ||
17 | + public $field; | ||
18 | + public $file; | ||
19 | + public $model; | ||
20 | + public $multi = false; | ||
21 | + public $gallery; | ||
22 | + public $size; | ||
23 | + public $name = 'Add file...'; | ||
24 | + public $remover = 0; | ||
25 | + | ||
26 | + public function init() | ||
27 | + { | ||
28 | + | ||
29 | + parent::init(); | ||
30 | + | ||
31 | + } | ||
32 | + | ||
33 | + public function run() | ||
34 | + { | ||
35 | + | ||
36 | + return $this->render( | ||
37 | + 'image_sizer', | ||
38 | + [ | ||
39 | + 'model' => $this->model, | ||
40 | + 'size' => $this->size, | ||
41 | + 'field' => $this->field, | ||
42 | + 'height' => $this->height, | ||
43 | + 'width' => $this->width, | ||
44 | + 'multi' => $this->multi, | ||
45 | + 'name' => $this->name, | ||
46 | + 'remover' => $this->remover, | ||
47 | + ] | ||
48 | + ); | ||
49 | + | ||
50 | + } | ||
51 | + | ||
52 | + public function getGallery() | ||
53 | + { | ||
54 | + if ($this->gallery) { | ||
55 | + $array = explode(",", $this->gallery); | ||
56 | + if (count($array) > 1) { | ||
57 | + array_pop($array); | ||
58 | + } | ||
59 | + return $array; | ||
60 | + } else { | ||
61 | + return []; | ||
55 | } | 62 | } |
56 | - return $array; | ||
57 | - } else { | ||
58 | - return array(); | 63 | + |
59 | } | 64 | } |
60 | - | ||
61 | - } | ||
62 | - | ||
63 | -} | ||
64 | \ No newline at end of file | 65 | \ No newline at end of file |
66 | + | ||
67 | + } | ||
65 | \ No newline at end of file | 68 | \ No newline at end of file |