Blog

ExtJS and Sencha Touch Themes and Templates

File Manager Extension

Jun 19, 2009 | English | By | 9 Comments | Leer en Español

I have created an extension based on Ext JS to select files from the server. So I would like to share this extension with you and see your point of view, so if there’s any bug please report it to me.

File Manager Extension
Author: Crysfel

I'm a software developer with 6+ years of experience, when I'm not developing software I may be writing a tutorial, you can follow me on twitter

Description

We can use this component to show the user the files he has in his FTP, or to select an image that is saved in the server and show it in some place; we have hundreds of possibles scenarios where we can use this component.

File Manager image

File Manager

Configuration properties

url (string): defines the URL where the requests are made using Ajax to obtain the directories the component will display, this property is required.

multiSelect (boolean): “true” if the component allows to select different files at the same time, by default is “false”.

filters (string): parameter sent to the server to filter the kind of files to be displayed, the format should be separated by spaces, if there’s more than one, for example “html htm jpg”.

root (string): this parameter specifies the directory that the component will display the first time, is important to remember that the server is not responsible to implement this functionality when sending the files to the assigned directory. By default is “/”.

params(object): parameters that will be send in every request to the server, these parameters will depend on your application.

You can use any configuration of the component “Ext.Window”, for example “title, width, height, etc.”

Methods

show(): this method displays the component on the screen.

You can invoke all the methods of the component “Ext.Window”.

Events

selectfile (Array files): is triggered when the user has selected one or more files, it receives an array as a parameter and it contains objects “Ext.data.Record” with the information of the files.

You can apply all the events that the component “Ext.Window” offers.

Parameters sent to the server

The following parameters are sent to the server through the method “POST”.

isForMainPanel (boolean): this parameter is sent to the server when the request has been made from the dataview store, is very useful to distinguish the requests from the main panel and the requests from the tree.

path (string): is the directory the user has selected to see, in the server we have to get and return the files underneath that directory.

filters (string): in this parameter we sent the file formats we want to filter, the server is reponsible to apply the file’s filter and return the files requested.

Server’s response

The server should return the information in JSON format.

For the folder tree in the left side, the structure of the JSON response needs to be like this:

[{"id":"1","text":"Name to show","url":"\/path\/tol\/the\/file","isFolder":true,"children":[]}]

If you have internal folders, the array “children” should have them defined, this is the structure proposed by the component “Ext.tree.TreePanel” so you must be familiar with it. The additional properties are: “url” which is the path of the file in the server and “isFolder” which is a boolean property that opens the folders when you click on them.

The structure is practically the same for the main panel, we only need to add the property “iconCls” which is a CSS class with the icon we want to show and the array of files must be in the “files” property.

{
files: [{...},{...}] //the previous structure
}

For the main panel is required to have the information returned by the server in a JSON object with the property “files”.

Ways of use

First we need to import the style sheets and the JavaScript component to the HTML like this:

<link rel="stylesheet" type="text/css" href="Ext.ux.FileManager/Ext.ux.FileManager.css" />
<script type="text/javascript" src="Ext.ux.FileManager/Ext.ux.FileManager.js"></script>

Just remember that first you need to include the Ext JS library.

The next thing we need to do is to create an instance of the component “FileManager” like this:

var manager = new Ext.ux.FileManager({
	url: 'getFiles.php'
}); 

manager.show();

To get the files that have been selected by the user we need to add a “listener” to the event “selectfile” like this:

manager.on('selectfile',function(files){
	console.debug(files);
});

Also you can do this by configuring the constructor like this:

var manager = new Ext.ux.FileManager({
	url: 'getFiles',
	listeners:{
		selectfile: function(files){
			console.debug(files);
		}
	}
});

To select more than one file at the same time:

var manager = new Ext.ux.FileManager({
	url: 'getFiles.php',
	multiSelect:true
});

Implementation in the server

The implementation on the server’s side must be written in any language you required according to your project’s needs, you just need to remember the previous specifications.

9 Responses to “File Manager Extension”

  • eddie Jul 15, 2009

    Hi, great script, thanks for sharing, just a question, is there an option to change the right window to a detailed list view of displayed folders / files ? thanks

    • Crysfel Jul 15, 2009

      Not in this version :( but it is a good idea and maybe in the next days i will add that feature, however, if you like to change it, you can modify the HTML in the XTemplate, it is really easy to do it ;)

  • JXL67 Oct 10, 2009

    My school system was almost entirely white and generally middle class. ,

  • JXL19 Oct 22, 2009

    Set an example for your neighbors. ,

  • slammer Sep 22, 2010

    How can I switch between HTTP protocols? It’s necesary when you use REST software architecture.

  • Art Nov 28, 2010

    Can you send me the link of demo file and I can download to see? It’s very nice app…

  • web file manager Dec 26, 2010

    web file manager

    FileVista is a web file manager for storing, managing and sharing files online through your web browser. It is a web based software which you install on your web server to fulfill web file management requirements of your company or organization. This web file manager allows your users to upload, download and organize any type of file with an intuitive user interface.

  • Lola Jul 25, 2011

    could you post your php file to get the files, thank you.

  • Jaime Handayan Oct 21, 2011

    Hi can i view the demo php backend?just for eductional purpose, I am working with my thesis

Leave a Reply







Updates

RSS

Subscribe to our feeds to receive updates of our newest posts and free tutorials.

Site search

Maybe we have what you need, would you like to search first?

Donations

Would you buy me a cup of coffee? I am sharing my knowledge and time with you, help this project grow. Thank you!