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
Requirements ¶
Tested with Yii 1.1.10, but should work with previous versions too
Usage ¶
0. Checkout source code to your project, for example to ext.elFinder
- Create controller for connector action, and configure it params
- ServerFileInput - use this widget to choose file on server using ElFinder pop-up
- ElFinderWidget use this widget to manage files
- To use TinyMceElFinder see: My TinyMce extension
// controller to host connector action
class ElfinderController extends CController
{
public function actions()
{
return array(
'connector' => array(
'class' => 'ext.elFinder.ElFinderConnectorAction',
'settings' => array(
'root' => Yii::getPathOfAlias('webroot') . '/uploads/',
'URL' => Yii::app()->baseUrl . '/uploads/',
'rootAlias' => 'Home',
'mimeDetect' => 'none'
)
),
);
}
}
//server file input
$this->widget('ext.elFinder.ServerFileInput', array(
'model' => $model,
'attribute' => 'serverFile',
'connectorRoute' => 'admin/elfinder/connector',
)
);
// ElFinder widget
$this->widget('ext.elFinder.ElFinderWidget', array(
'connectorRoute' => 'admin/elfinder/connector',
)
);
Changelog ¶
- January 16, 2013 Fixed jQuery 1.8.3 compatibility, added CSRF validation support, added i18n support, begin using compressed script when not debugging
- August 14, 2012 Fixed bug with upload(from comments here)
July 18, 2012 Adding support for multiple ServerFileInput instances with different connectors
Resources ¶
- Extension github page (moved from bitbucket page )
- TinyMce extension
- ElFinder page
I can not adjust
I installed your extension, but when I click "choose file" I get the message: Unable to connect to backend!. What I missed?
Re: I can not adjust
Check connectorRoute passed to widget: is “connector” action properly configured? “uploads” directory exists and is writable for webserver process?
(your can read more about connector options in elFinder 1.x wiki).
Also, if something wrong in backend configuration options(connectorRoute to which is passed), you can see server response in network tab with chrome developer tools(or in something similar, with tools, what you are using) - it can be very helpfull to determine problem which you has.
can't take file by CUploadedFile::getInstance
Ok i have configure widget and it's work very well, but i can't take file by CUploadedFile::getInstance, when i write in controller:
$model->icon=CUploadedFile::getInstance($model,'icon');
this is widget:
$this->widget('ext.elFinder.ServerFileInput', array( 'model' => $model, 'attribute' => 'icon', 'connectorRoute' => '/elfinder/connector', ) );
Re: can't take file by CUploadedFile::getInstance
This is because $model->icon is not file field - it is text field with file url on server.
$model->icon is not file field - it is text field with file url on server
As i understood this widget insert text field in form. Can i change it to file field?
re: $model->icon is not file field - it is text field with file url on server
No, because file selected in this widget already on server, widget is only to pick file url on server.
You can save this url for use in your app. Also according to your connector cofiguration you can get file path on server and for example copy it somewhere.
CSRF Problem
Thanks for this great extension.
When i have active CSRF, i cant upload files. some one knows how resolve this problem?
Thanks.
Re: CSRF problem
In elFinder source code I have found support for "Rails csrf meta tag".
So you can add Yii CSRF token to elFinder using the same meta tags:
//place this in your page header $request=Yii::app()->request; if($request->enableCsrfValidation){ echo CHtml::metaTag($request->csrfTokenName,'csrf-token'); echo CHtml::metaTag($request->getCsrfToken(),'csrf-param'); }
CSRF
Sorry for my ignorance, where exactly i need introduce this code? "page header", i have a "actionAdmin" on controller an view "admin" where i show elFinder.
Another question, for what you didnt introduce new version of elFinder?, is on RC1. Is easy to change to version 2?
Re: CSRF
About where to place meta-tags
Place that code in head tag of html page(maybe it is in your layout)
About elfinder 2.x
As I seen elFinder in general was rewrited in 2.x branch, so there are many new features and new interface.
I have made it integration as separate widget, and - it works ok.
Also I have started work on integration with TinyMCE, and there is one problem - now elFinder has no option to open in modal dialogue. So we need to open it in iframe(as described in elFinder wiki about integration with tinyMCE) or write code to properly open it in modal dialogue. About opening it in iframe - at my mind it is too ugly(i have tried and do not like this at all), most ugliest thing in it - is modal dialogues opened from elFinder within iframe. About second one - in my current realization it also looks bad.
So, because I have no need in new features right now, I decided do not continue developing extension for elFinder 2.x until official release. Or until i have more free time for this.
Anyway I have published it here: elFinder 2.x on bitbucket . So you can try it.
Adding support for multiple instances with different connectors
Not sure if there was a supported way to do this, but I wanted several fields using elFinder on the same page. Unfortunately, only the last widget's connector path was used, which messes things up if your multiple fields require different locations on your server (and the other settings that you can set in the connector). So...
I've edited the ServerFileInput.php to change how the javascript is rendered on the page. In this file find the run() method and swap out the following code: (starts at line 80)
$script = <<<EOD window.elfinderBrowse = function(field_id, connector) { var aFieldId = field_id, aWin = this; if($("#elFinderBrowser").length == 0) { $("body").append($("<div/>").attr("id", "elFinderBrowser")); var settings = $settings; settings["url"] = connector; $("#elFinderBrowser").elfinder(settings); } else { $("#elFinderBrowser").elfinder("open", connector); } } EOD; $cs = Yii::app()->getClientScript(); $cs->registerScript('ServerFileInput#global', $script); $js = //'$("#'.$id.'").focus(function(){window.elfinderBrowse("'.$name.'")});'. '$("#' . $id . 'browse").click(function(){window.elfinderBrowse("' . $id . '", "'.$connectorUrl.'")});';
For noobs (including myself) who didn't know you can include multiple settings in the single connector controller e.g.
class ElfinderController extends CController { public function actions() { return array( 'connector' => array( 'class' => 'ext.elFinder.ElFinderConnectorAction', 'settings' => array( 'root' => Yii::getPathOfAlias('webroot') . '/images/', 'URL' => '', 'rootAlias' => 'Image', 'mimeDetect' => 'none' ) ), 'mediaconnector' => array( 'class' => 'ext.elFinder.ElFinderConnectorAction', 'settings' => array( 'root' => Yii::getPathOfAlias('webroot') . '/media/', 'URL' => '', 'rootAlias' => 'Media', 'mimeDetect' => 'none' ) ), ); } }
Re: Adding support for multiple instances with different connectors
Added your changes to extension
A problem on Host server
Everything worked great locally, but on upload to the server (PHP Version 5.2.17, Linux) I had a connector problem.
On inspecting the response I got the following error:
PHP Error [2] array_keys() [function.array-keys]: The first argument should be an array (pathtofile/protected/extensions/elFinder/php/elFinder.class.php:325)
I had to edit the line to: (adding the &&count($this->_options['archivers'])>0)
if (isset($this->_commands['extract'])&&count($this->_options['archivers'])>0) {
which solved it. (I know this is a elFinder core problem, but I wanted you guys to have the solution at hand if you ran into the same problem :)
zip/unzip
How can i add zip/unzip button to panel?
Re: How can i add zip/unzip button to panel?
There is settings property where you can override default widget settings, you can read more about these options here:
https://github.com/Studio-42/elFinder/wiki/elFinder-1.x#client-configuration
But as I remember, by default, there is all avaliable buttons on toolbar, so - in order to add these buttons to toolbar probably you will need to modify elFinder scripts.
How can i add zip/unzip button to panel
there are no those buttons. Check it out. I was donwload last version of ext. and i has no change any files.
migrate to yii2
Hi, are you already working on a yii2 version of this extension?
Would be cool to know, as I would love to use this extension in my new "internal" intranet site...
Re: migrate to yii2
Not yet, I think before doing this we need to wait at least for the alpha version.
include(TinyMceFileManager.php): failed to open stream: No such file or directory
I'm trying to implement TinyMCE/ElFinder in my Yii application. After installing both extensions and creating the two accompanying controllers, I get the error message
include(TinyMceFileManager.php): failed to open stream: No such file or directory
. This arises from the class definitionclass TinyMceElFinder extends TinyMceFileManager
in TinyMceElFinder.php. Can you give me any guidance on how I should remedy this situation?TinyMCE works great until I enable ElFinder.
include(TinyMceFileManager.php): failed to open stream: No such file or directory
This is because TinyMceFileManager is not in imports paths..
To fix this you can add to you import paths.
You can import just before use Yii::import('ext.tinymce.TinyMceFileManager'), or in application configuration(personally I have imported both extensions in application configuration):
'import'=>array( //... 'ext.tinymce.*', 'ext.elFinder.*', //... )
Import Path
Thanks for the information on adding TineMCE and ElFinder to the import paths in config/main.php. I thought it was strange that the instructions didn't say to do that, but I figured that there must be a reason not to since they didn't included it. Anyway, adding them to the import array resolved that problem.
Now, I'm getting the infamous "Unable to connect to backend." Then, I have to figure out how to use the ElfinderController and TinyMceController since they never get used in your instructions. And how to integrate ElFinder with TinyMCE since your instructions only relate to independent ElFinder widgets.
Re: Import path
This controllers is examples how to use actions from extensions in your application, also *Route properties in examples are pointing to that controllers.
The only thing you need, to use that controllers, is to put them somewhere in application and specify correct routes in widgets, thats is all.
To integrate ElFinder with TinyMCE, you need to have working ElFinderConnectorAction(there is an example in ElfinderController above), and fileManager configuration for TinyMce(example also is provided on extension page):
'fileManager' => array( 'class' => 'ext.elFinder.TinyMceElFinder', 'connectorRoute'=>'admin/elfinder/connector', ),
toolbar not displaying / javascript not loading ?
Thanks for your work on this extension.
I'm having a problem. The TinyMCE toolbar is not displaying, and I'm getting the following javascript error:
Error: TypeError: $(...).tinymce is not a function
Seems the JS file may not be loading?
Compressor Route
It seems the problem is with the compressor route. When I remove the compressor route from the widget code, tinyMCE loads as it should.
Re: Compressor Route
Just updated extension, try updated version (there was bug with caching in compressor action)
Compressor still causing problems...
Thanks for the fast turn-around, Bogdan. I installed the new version you sent and it still throws a ".tinymce is not a function" error.
(Apologies everyone. I realize we're talking about newtinymce in the elfinder page, but they're intimately related)
Re: Compressor still causing problems...
Looks, like, you have two jquery scripts on page(details in PM)
Anyway, comments is not good place for this discussion - let continue in PM or on extension issue tracker
Upgrade to version 2.0
Any interest in upgrading to version elFinder 2.0? It is on RC1 right now, I can help with either coding aspect of it or some $$ for your time.
Permission
I have different folders in elFinder: hr, accountant, admin, employee.
I have Yii roles ( hr, accountant, admin, employee). Is there a way that specific Yii roles access to only that folder. Lets say a Yii roles accountant can only have access (read and upload , delete files ) to accountant folder but not other folders like hr, admin , employee. Thank you for your help.
Re: Permission
As i remember there is some configuration options related to permissions in elFinder connector, so you can try to configure it using user iformation.
But, maybe the best option would be to create separete connector actions for separate resources, and setup access filters for them.
elfinder Jquery
When elfinder runs, it generates asset folder with jquery and jquery ui in it. Do u know where can i specify elfinder to use a specific jquery and jquery ui version ? It works with jquery 1.8.3 , but it is not working with latest jquery 1.9.0.
Great!!!
tanx alot ;)
Multiple Roots?
Hi, can I set up multiple roots and set the folder permission?
Also, I got a error on elfinder with tinymce.
Uncaught TypeError: Cannot set property 'value' of undefined
How can I fix it? Thanks!
Usage with TinyMCE 4.x
Line 89 of TinyMceElFinder:
change
aWin.document.forms[0].elements[aFieldName].value = url;
to
Couldn't select the image before that to pass it to the TinyMCE image field.
Usage with TinyMCE 4.x
uploaded latest extension version(with tinyMCE 4.x support)
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.