1f90c5f4
Karnovsky A
ArtboxImage resizer
|
1
2
3
4
|
<?php
namespace common\components\artboximage;
|
98e8e9e5
Karnovsky A
ArtboxImage uploader
|
5
|
use kartik\file\FileInput;
|
1f90c5f4
Karnovsky A
ArtboxImage resizer
|
6
7
8
|
use Yii;
use yii\base\Component;
use yii\base\ErrorException;
|
a123b4b4
Karnovsky A
ArtboxImage uploader
|
9
|
use yii\helpers\Html;
|
1f90c5f4
Karnovsky A
ArtboxImage resizer
|
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
use yii\image\drivers\Image;
//use common\components\artboximage\drivers\Image;
class ArtboxImage extends Component {
public $driver;
public $presets = [];
public $rootPath;
public $rootUrl;
public $extensions = [
'jpg' => 'jpeg',
'jpeg' => 'jpeg',
'png' => 'png',
'gif' => 'gif',
'bmp' => 'bmp',
];
|
98e8e9e5
Karnovsky A
ArtboxImage uploader
|
31
32
|
public $uploadUrl = '/admin/artboxfile/action/upload';
|
1f90c5f4
Karnovsky A
ArtboxImage resizer
|
33
34
35
36
37
38
|
public function load($file = null, $driver = null) {
if(empty($file) || !realpath($file)) {
throw new ErrorException('File name can not be empty and exists');
}
return Image::factory($file, $driver ? $driver : $this->driver);
}
|
98e8e9e5
Karnovsky A
ArtboxImage uploader
|
39
40
41
42
43
44
45
46
47
48
49
50
51
|
public function fileinputWidget($model, $modelField, $formField = 'fileUpload', $multiple = false, $imageOnly = true) {
$options = [
'multiple' => $multiple,
];
if ($imageOnly) {
$options['accept'] = 'image/*';
}
return FileInput::widget([
'name' => $formField,
'options' => $options,
'pluginOptions' => [
'allowedFileExtensions' => array_keys($this->extensions),
|
a123b4b4
Karnovsky A
ArtboxImage uploader
|
52
|
'initialPreview' => $model->{$modelField} ? Html::img($model->{$modelField}) : '',
|
98e8e9e5
Karnovsky A
ArtboxImage uploader
|
53
54
|
'overwriteInitial' => !$multiple,
'showRemove' => true,
|
55b984ad
Karnovsky A
---
|
55
56
|
'showUpload' => true,
'showCaption' => false,
|
98e8e9e5
Karnovsky A
ArtboxImage uploader
|
57
58
59
60
61
62
|
'uploadUrl' => $this->uploadUrl,
'uploadExtraData' => [
'fileField' => $modelField,
'multiple' => intval($multiple),
],
],
|
a123b4b4
Karnovsky A
ArtboxImage uploader
|
63
|
'pluginEvents' => [
|
55b984ad
Karnovsky A
---
|
64
65
66
|
"change" => "function() {
alert('_change');
}",
|
a123b4b4
Karnovsky A
ArtboxImage uploader
|
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
"open" => "function() { console.log('open'); }",
"save" => "function() { console.log('save'); }",
"upload" => "function() { console.log('upload'); }",
"uploaded" => "function() { console.log('uploaded'); }",
"filepreupload" => "function() { console.log('filepreupload'); }",
"fileuploaded" => "function(event, files, extra) { console.log(event, files, extra); }",
"fileuploaderror" => "function() { console.log('fileuploaderror'); }",
"filebatchuploaderror" => "function() { console.log('filebatchuploaderror'); }",
"filebatchuploadsuccess" => "function() { console.log('filebatchuploadsuccess'); }",
"filebatchuploadcomplete" => "function() { console.log('filebatchuploadcomplete'); }",
'filebatchuploadsuccess' => "function(event, files, extra) {
console.log(event, files, extra);
}",
],
|
98e8e9e5
Karnovsky A
ArtboxImage uploader
|
81
82
|
]);
}
|
1f90c5f4
Karnovsky A
ArtboxImage resizer
|
83
|
}
|