Although the tutorial is Russian, don't worry, just follow the code on the line steps: 1, use composer to install extension composerrequire -- prefer-distmihaildevyii2-elfinder & quot; * & quot; Yii2 extension: https://github.com/MihailDev/yii2-elfinder
Although the tutorial is in Russian, don't worry, just do it by code.
Steps:
1. use composer to install extensions
Composer require -- prefer-dist mihaildev/yii2-elfinder "*"
2. Add configuration information. I am a Yii2 advanced template and used in the background. open the backend/config/main. php configuration file.
Added at the same level as 'components'
'Controllermap' => ['elfinder '=> ['class' => 'mihaildev \ elfinder \ pathcontroller', 'access' => [' @ '], 'root' => ['path' => 'uploads', // main directory path 'name' => 'Files'], /* 'watermark' => ['source' => _ DIR __. '/logo.png', // Path to Water mark image' marginRight '=> 5, // Margin right pixel 'marginbottom' => 5, // Margin bottom pixel 'quality' => 95, // JPEG image save quality 'transparency '=> 70, // Water mark image transparency (other than PNG) 'targettype' => IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP, // Target image formats (bit-field) 'targetminpixel' => 200 // Target image minimum pixel size] */],
3. add default parameters
Open commmon (backend)/config/params. php
// Elfinder default configuration 'elfinderultconfig' => ['language' => 'zh _ cn', 'controller' => 'elfinder ', // Default control name 'filter' => 'image', // only manage picture https://github.com/Studio-42/elFinder/wiki/Client-configuration-options#wiki-onlyMimes 'template' =>'{Input} {button}
', 'Options' => ['class' => 'form-control'], 'buttonoptions' => ['class' => 'btn btn-default'], 'buttonname' => 'browsed '],
4. introduce the call in the last step.
Open the form view file to be used and add the following code:
Use mihaildev \ elfinder \ InputFile;
Params ['elfinderultconfig'], ['path' => $ dir]); echo $ form-> field ($ model, 'carlogo ')-> widget (InputFile :: className (), $ elfinderConfig);?>
Final effect: