1. Go to this page and download the library: Download razonyang/yii2-uploader 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/ */
class UploadForm extends \yii\base\Model
{
use \RazonYang\Yii2\Uploader\UploadModelTrait;
public function handle()
{
if (!$this->validate()) {
// handles error
throw new \Exception('invalid file');
}
$url = $this->upload();
return [
'url' => $url,
// ... other information
];
}
}
class UploadController extends \yii\web\Controller
{
public function actionUpload()
{
$form = new UploadForm([
'file' => \yii\web\UploadedFile::getInstanceByName('file')
]);
return $form->handle();
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.