troy / yii2-image-upload
upload image via ajax
Package info
github.com/lygfanye/yii2-image-upload
Language:JavaScript
Type:yii2-extension
pkg:composer/troy/yii2-image-upload
1.0
2014-12-17 03:01 UTC
Requires
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2026-03-10 14:08:40 UTC
README
upload image via ajax
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist troy/yii2-image-upload ""
or add
"troy/yii2-image-upload": ""
to the require section of your composer.json file.
Usage
Once the extension is installed, simply use it in your code by :
<a id="imageUpload" href="javascript:;">上传图片</a>
<?= \troy\ImageUpload\ImageUpload::widget(
[
'targetId' => 'imageUpload',//html dom id
'config' =>[
'action' =>Yii::$app->getUrlManager()->createUrl(['site/index'])
]
]
); ?>
You also can add some events for it such as onComplete function
<?=
.....
use yii\web\JsExpression;
.....
\troy\ImageUpload\ImageUpload::widget(
[
'targetId' => 'imageUpload',//html dom id
'config' =>[
'action' =>Yii::$app->getUrlManager()->createUrl(['site/index']),
'onComplete' => new JsExpression("function(fileName, responseJSON){ something todo...... }")
]
]
);
?>
if you want to the the UploadAction in this ext you can use :
class SiteController extends Controller
{
public function actions()
{
return [
'upload' => [
'class' => 'troy\ImageUpload\UploadAction',
'successCallback' => [$this, 'successCallback'],
'beforeStoreCallback' => [$this,'beforeStoreCallback']
],
]
}
public function successCallback($store,$file)
{
}
public function beforeStoreCallback($file)
{
}
}