File Chooser

Rating: 3.9/5 (16 votes)

A file chooser control the retrieve file/directory information via a user-provided function. Most function handlers will communicate with a server via XMLHttpRequest. When selecting a file, if the file is an image, a preview will display in the right panel. To open the chooser, click the icon at the right side of the input box.

Note: Due to limitations in Internet Explorer, if you wish to use the file upload feature, you MUST define a hidden iframe in the page having both a name and id of "hidden_iframe".

Demo

File:

Download

File Chooser is available under the terms of the GNU General Public License.

Source:

Global dependencies for all controls:

Usage

Constructor:

var chooser = new Control.FileChooser(element, handler, options);

Parameters:

Additional Options:

Example:

new Control.FileChooser('my_filechooser', listUserFiles, { icon: '/images/filechooser.png', parentImage: '/images/parent.gif', fileImage: '/images/file.gif', directoryImage: '/images/directory.gif' });

File Handling Function

The file listing function takes two parameters: directory and callback. Callback is a function reference passed by the File Chooser object. The listing function is expected to create an object with the following structure and pass it back via the callback function:

{"path":"/test", "parent":"/", "status":"success", "files":[ {"type":"directory", "name":"test", "size":0,"path":"/mydir"}, {"type":"file", "name":"logo.tiff", "size":264156, "url":"/software/js/filestore/logo.tiff"}, {"type":"file", "name":"photo.jpg", "size":13792, "url":"/software/js/filestore/photo.jpg"} ], "fileManager":"/software/js/fileManager.php"}

The fileManager property is used by File Chooser to upload files, create and delete directories, and delete files. The HTTP requests sent for those tasks use the following parameters:

Additional parameters for "upload":

Additional parameters for "createdir":

Additional parameters for "delete":

Examples:

http://<fileManager>?a=createdir&p=mydir/test&d=newdir http://<fileManager>?a=delete&p=mydir&f=myimage.jpg

Simple PHP file manager: