Richie is an Entrepreneur, a Technologist and Cloud Architect. Loves how technologies brings the promise of an easier life, but enjoys the challenge to make it work. Work achievements, play, & fatherhood are the things that drive Richie.
ExtJS has a lot of great components to build complete web application that can be look like desktop application, In today post I want to show how to create a very simple file browser in ExtJS, with PHP backend we can easily get file and folder on the system.
First this example have some limitation, I try it on my XAMPP localhost, so I assumed the it is the top parent of all directories, the tree directory only load once when the page is loaded, file preview only in grid component.
The example container is based on window component, which have two items inside, they are treePanel and gridPanel, the gridPanel will load dynamically, trigerred when user click on of the tree node.
This file is for fetching all directory on your XAMPP htdocs directory, using $_SERVER[‘DOCUMENT_ROOT’] variable. If you have many directory on htdocs, it will take time to load. In this php file I used a recursive function to get all the directory with all the sub directory by one call function, that’s why it will take time to load, and create a json format from it.
$dh = opendir($dir); $files = array(); while (($file = readdir($dh)) !== false) { if ($file != '.' AND $file != '..' ) { if (filetype($dir . $file) == 'file') { $files[] = array( 'filename' => $file, 'filesize' => filesize($dir . $file). ' bytes', 'filedate' => date("F d Y H:i:s", filemtime($dir . $file)) ); } } } closedir($dh);
echo(json_encode(array('files' => $files)));
?>
Well that all hope can give some idea to create much larger application or adding some more feature like icons view (using DataView component), create, edit, delete file, etc.