This extension allows use elFinder file manager in your Yii application. Possible usage:
- chose file on server side (ServerFileInput widget)
- manage files in specified folder (ElFinder widget)
- add file browser to tinyMce wysiwyg editor
Based on elfinder extension by Bogdan Savluk with updated elFinder and some code improvements.
Requirements ¶
Tested with Yii 1.1.14, but should work with previous versions too.
Installation ¶
Copy extension files to your project to protected/extensions/elFinder
Usage ¶
- Create controller for connector action, and configure it params
~~~
[php]
class ElfinderController extends Controller {
// don't forget configure access rules
public function actions() {
return array(
// main action for elFinder connector
'connector' => array(
'class' => 'ext.elFinder.ElFinderConnectorAction',
// elFinder connector configuration
// https://github.com/Studio-42/elFinder/wiki/Connector-configuration-options
'settings' => array(
'roots' => array(
array(
'driver' => 'LocalFileSystem',
'path' => Yii::getPathOfAlias('webroot') . '/files/',
'URL' => Yii::app()->baseUrl . '/files/',
'alias' => 'Root Alias',
'acceptedName' => '/^[^\.].*$/', // disable creating dotfiles
'attributes' => array(
array(
'pattern' => '/\/[.].*$/', // hide dotfiles
'read' => false,
'write' => false,
'hidden' => true,
),
),
)
),
)
),
// action for TinyMCE popup with elFinder widget
'elfinderTinyMce' => array(
'class' => 'ext.elFinder.TinyMceElFinderPopupAction',
'connectorRoute' => 'connector', // main connector action id
),
// action for file input popup with elFinder widget
'elfinderFileInput' => array(
'class' => 'ext.elFinder.ServerFileInputElFinderPopupAction',
'connectorRoute' => 'connector', // main connector action id
),
);
}
}
~~~
ServerFileInput - use this widget to choose file on server using elFinder pop-up
[php] $this->widget('ext.elFinder.ServerFileInput', array( 'model' => $model, 'attribute' => 'field_name', 'popupConnectorRoute' => 'elfinder/elfinderFileInput', // relative route for file input action // ability to customize "Browse" button // 'customButton' => TbHtml::button('Browse images', array( // 'id' => TbHtml::getIdByName(TbHtml::activeName($model, 'field_name')) . 'browse', // 'class' => 'btn', 'color' => TbHtml::BUTTON_COLOR_DEFAULT, // 'size' => TbHtml::BUTTON_SIZE_DEFAULT, 'style' => 'margin-left:10px;')), // title for popup window (optional) 'popupTitle' => 'Files', ));
ElFinderWidget - use this widget to manage files
[php] $this->widget('ext.elFinder.ElFinderWidget', array( 'connectorRoute' => 'elfinder/connector', // relative route for elFinder connector action ));
TinyMceElFinder - use this widget to integrate elFinder with yii-tinymce
[php] $this->widget('ext.tinymce.TinyMce', array( 'model' => $model, 'attribute' => 'content', 'fileManager' => array( 'class' => 'ext.elFinder.TinyMceElFinder', 'popupConnectorRoute' => 'elfinder/elfinderTinyMce', // relative route for TinyMCE popup action // title for popup window (optional) 'popupTitle' => "Files", ), ));
can not create a new folder ?
elfinder can not create a new folder ?
Re: can not create a new folder ?
Try new release. I switched to elFinder 2.x branch, it should be more stable.
can not create a new folder ?
Ok...successful...thanks very much
create and extract archive
how to create and extract archive in elfinder ?
Re: create and extract archive
It should work out of the box, if you have enable
proc_open()
function in your hosting. You need just upload archive and you should be able to extract it.elfinder2 css conflict with bootstrap twitter
i still have no idea to fix elfinder2 css with bootstrap twitter, so the best version elfinder that works with BT is elFinder 1.2, that i use today..
Re: elfinder2 css conflict with bootstrap twitter
The best solution right now is run elFinder in simple iframe without TB. ServerFileInput and TinyMceElFinder works in this way.
custom button
I don't need all buttons of toolbar. So how can I disable the buttons of toolbar??
Re: custom button
Try something like that in popup action configuration (not tested):
// action for file input popup with elFinder widget 'elfinderFileInput' => array( 'class' => 'ext.elFinder.ServerFileInputElFinderPopupAction', 'connectorRoute' => 'connector', // main connector action id, 'settings' => array( 'uiOptions' => array( // toolbar configuration 'toolbar' => array( ['quicklook', 'editimage'], /*['copy', 'cut', 'paste'],*/ ), ), ), ),
https://stackoverflow.com/a/16606500
custom button in tinymce
Isn't this a way for custom elfinder button in tinymce?? I see no change with this.. can I get help on this plz??
function elFinderBrowser (field_name, url, type, win) { tinymce.activeEditor.windowManager.open({ file: adminUrl +'elFinder/elfinderTinyMce', title: 'File Manager', width: 900, height: 450, resizable: 'yes', uiOptions: { toolbar : [ ['open'], ['back', 'forward'], ['reload'], ['home', 'up'], ['mkfile', 'upload'], ['info'], ['quicklook'], ['copy', 'cut', 'paste'], ['rm'], ['duplicate', 'rename', 'edit'], ['extract', 'archive'], ['search'], ['view'], ] }, }, { setUrl: function (url) { win.document.getElementById(field_name).value = url; } } ); return false; }
Re: custom button in tinymce
Like I said, you should add this into configurations of action that displays popup with elfinder (in ElfiderController).
Change root on user
Hello,
This is a great extension!
But i'm tring to change/set different root per function, so i want to define root with different path for some forms.
It is possible?
Thanks for your work
Rre: Change root on user
Try to define many connector actions with different configuration eg:
// public function actions() { return array( 'connectorFirst' => array( // config ), 'connectorSecond' => array( // config ), 'elfinderTinyMceFirst' => array( 'class' => 'ext.elFinder.TinyMceElFinderPopupAction', 'connectorRoute' => 'connectorFirst', ), 'elfinderTinyMceSecond' => array( 'class' => 'ext.elFinder.TinyMceElFinderPopupAction', 'connectorRoute' => 'connectorSecond', ), ); }
Re: Change root on user
Thanks, it works :)
uiOptions
I have read the comments and i have tried use the uiOptions with toolbar, it didn't work... any advices?
Also its possible to update to rc1?
Thanks
Re: uiOptions
This extension use elFinder in newer version than rc1.
I never use uiOptions so i can't help you, especially if I can't see your code.
Re: uiOptions
Oh ok, nice to know thats the newest version :)
my code is the following:
'connectorAvisos' => array( 'class' => 'ext.elFinder.ElFinderConnectorAction', // elFinder connector configuration // https://github.com/Studio-42/elFinder/wiki/Connector-configuration-options 'settings' => array( //'locale' => 'pt.UTF-8', 'uiOptions' => array( // toolbar configuration 'toolbar' => array( array('quicklook', 'editimage'), ), ), 'roots' => array( array( 'driver' => 'LocalFileSystem', 'path' => Yii::getPathOfAlias('webroot') . '/../files/avisos', 'URL' => '/', 'alias' => 'Avisos', 'acceptedName' => '/^[^\.].*$/', // disable creating dotfiles 'attributes' => array( array( 'pattern' => '/\/[.].*$/', // hide dotfiles 'read' => false, 'write' => false, 'hidden' => true, ), ), 'uploadMaxSize' => '5M', 'uploadAllow' => $INTRAFORBOX_ALLOWED_MIMETYPES, # allow any images 'uploadDeny' => array('all'), 'uploadOrder' => 'deny,allow' ) ), ) ),
Also image thumbnail is not showing on finder, but they are created on server without problem.
Re: uiOptions
You should use uiOptions in popup action (eg. 'elfinderTinyMce'), not in connector action. I gave an example here: http://www.yiiframework.com/extension/yii-elfinder2/#c18112
Re: uiOptions
Oh, ok... i was asking for ui buttons for elfinder toolbar not tinymce, any way to disable from elfinder?
Re: uiOptions
In example 'elfinderTinyMce' is a action, that display popup with elFinder for TinyMCE - settings are apply to elFinder, not TinyMce.
Changing buttons
To change the buttons on a widget, in the view use:
$this->widget('ext.elFinder.ElFinderWidget', array( 'connectorRoute' => 'elfinder/connector', // relative route for elFinder connector action 'settings' => array( 'uiOptions' => array( // toolbar configuration 'toolbar' => array( ['copy', 'cut', 'paste'], ), ), ), ));
Can not set autoresize and watermark on file upload.
Can you provide instructions how to use the autoresize and watermark plugins?
re:Can not set autoresize and watermark on file upload.
Finally i found the correct configuration of action.
public function actions() { $pngLogoPath=Yii::getPathOfAlias('webroot') . '/files/'.'logo.png'; $opts = array( // main action for elFinder connector 'connector' => array( 'class' => 'ext.elFinder.ElFinderConnectorAction', // elFinder connector configuration // https://github.com/Studio-42/elFinder/wiki/Connector-configuration-options 'settings' => array( 'bind' => array( 'upload.presave' => array( 'Plugin.AutoResize.onUpLoadPreSave', 'Plugin.Watermark.onUpLoadPreSave', ) ), 'plugin' => array( 'AutoResize' => array( 'enable' => true, // For control by volume driver 'maxWidth' => 500, // Path to Water mark image 'maxHeight' => 500, // Margin right pixel 'quality' => 95, // JPEG image save quality 'preserveExif' => false, // Preserve EXIF data (Imagick only) 'forceEffect' => false, // For change quality or make progressive JPEG of small images 'targetType' => IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP, // Target image formats ( bit-field ) 'offDropWith' => null, // Enabled by default. To disable it if it is dropped with pressing the meta key // Alt: 8, Ctrl: 4, Meta: 2, Shift: 1 - sum of each value // In case of using any key, specify it as an array 'onDropWith' => null // Disabled by default. To enable it if it is dropped with pressing the meta key // Alt: 8, Ctrl: 4, Meta: 2, Shift: 1 - sum of each value // In case of using any key, specify it as an array ), 'Watermark' => array( 'enable' => true, // For control by volume driver 'source' => $pngLogoPath, // Path to Water mark image 'ratio' => 0.2, // Ratio to original image (ratio > 0 and ratio <= 1) 'position' => 'RB', // Position L(eft)/C(enter)/R(ight) and T(op)/M(edium)/B(ottom) 'marginX' => 5, // Margin horizontal pixel 'marginY' => 5, // Margin vertical 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 'interlace' => IMG_GIF | IMG_JPG, // Set interlacebit image formats ( bit-field ) 'offDropWith' => null, // Enabled by default. To disable it if it is dropped with pressing the meta key // Alt: 8, Ctrl: 4, Meta: 2, Shift: 1 - sum of each value // In case of using any key, specify it as an array 'onDropWith' => null // Disabled by default. To enable it if it is dropped with pressing the meta key // Alt: 8, Ctrl: 4, Meta: 2, Shift: 1 - sum of each value // In case of using any key, specify it as an array ) ), 'roots' => array( array( 'driver' => 'LocalFileSystem', 'path' => Yii::getPathOfAlias('webroot') . '/files/', 'URL' => Yii::app()->baseUrl . '/files/', 'plugin' => array( 'AutoResize' => array( 'enable' => true, // For control by volume driver 'maxWidth' => 500, // Path to Water mark image 'maxHeight' => 500, // Margin right pixel 'quality' => 95, // JPEG image save quality 'preserveExif' => false, // Preserve EXIF data (Imagick only) 'forceEffect' => false, // For change quality or make progressive JPEG of small images 'targetType' => IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP, // Target image formats ( bit-field ) 'offDropWith' => null, // Enabled by default. To disable it if it is dropped with pressing the meta key // Alt: 8, Ctrl: 4, Meta: 2, Shift: 1 - sum of each value // In case of using any key, specify it as an array 'onDropWith' => null // Disabled by default. To enable it if it is dropped with pressing the meta key // Alt: 8, Ctrl: 4, Meta: 2, Shift: 1 - sum of each value // In case of using any key, specify it as an array ), 'Watermark' => array( 'enable' => true, // For control by volume driver 'source' => $pngLogoPath, // Path to Water mark image 'ratio' => 0.2, // Ratio to original image (ratio > 0 and ratio <= 1) 'position' => 'RB', // Position L(eft)/C(enter)/R(ight) and T(op)/M(edium)/B(ottom) 'marginX' => 5, // Margin horizontal pixel 'marginY' => 5, // Margin vertical 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 'interlace' => IMG_GIF | IMG_JPG, // Set interlacebit image formats ( bit-field ) 'offDropWith' => null, // Enabled by default. To disable it if it is dropped with pressing the meta key // Alt: 8, Ctrl: 4, Meta: 2, Shift: 1 - sum of each value // In case of using any key, specify it as an array 'onDropWith' => null // Disabled by default. To enable it if it is dropped with pressing the meta key // Alt: 8, Ctrl: 4, Meta: 2, Shift: 1 - sum of each value // In case of using any key, specify it as an array ) ), 'alias' => 'Root Alias', 'acceptedName' => '/^[^\.].*$/', // disable creating dotfiles 'attributes' => array( array( 'pattern' => '/\/[.].*$/', // hide dotfiles 'read' => false, 'write' => false, 'hidden' => true, ), ), ) ), ) ), // action for TinyMCE popup with elFinder widget 'elfinderTinyMce' => array( 'class' => 'ext.elFinder.TinyMceElFinderPopupAction', 'connectorRoute' => 'connector', // main connector action id ), // action for file input popup with elFinder widget 'elfinderFileInput' => array( 'class' => 'ext.elFinder.ServerFileInputElFinderPopupAction', 'connectorRoute' => 'connector', // main connector action id ), ); return $opts; }
You wrote "Create controler for connector" - sory maby i'm too dumb but where i should place this controller and what name should it have?
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.