1. Go to this page and download the library: Download troy/yii2-image-upload library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
troy / yii2-image-upload example snippets
<?= \troy\ImageUpload\ImageUpload::widget(
[
'targetId' => 'imageUpload',//html dom id
'config' =>[
'action' =>Yii::$app->getUrlManager()->createUrl(['site/index'])
]
]
);
<?=
.....
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...... }")
]
]
);
php composer.phar
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)
{
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.