PHP code example of rmrevin / yii2-file
1. Go to this page and download the library: Download rmrevin/yii2-file 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/ */
rmrevin / yii2-file example snippets
<?
// ...
return [
// ...
'modules' => [
// ...
'file' => [
'class' => '\rmrevin\yii\module\File\Module',
'upload_alias' => '@app/web/upload',
'upload_web_alias' => '/upload',
'storage_alias' => '@app/web/storage',
'storage_web_alias' => '/storage',
'max_upload_file_size' => 10, // megabytes
],
],
];
use rmrevin\yii\module\File;
// external resource
$File = File\models\File::push(new File\component\ExternalResource('https://www.google.ru/images/srpr/logo11w.png'));
// internal resource
$File = File\models\File::push(new File\component\InternalResource('/var/www/images/pick.png'));
// uploaded resource
$File = File\models\File::push(new File\component\UploadedResource(UploadedFile::getInstance($model, 'file')));
use rmrevin\yii\module\File;
$File = File\models\File::find()->one();
echo Html::img((string)$File->image()
->resizeByWidth(100));
// available methods: resize, resizeByWidth, resizeByHeight, crop, thumbnail, watermark, text