PHP Ajax File Browser

New Version: Ajax File Browser 2.0 Beta, this version is no longer supported.

As the new buzz technology is developing, I realised I had no real evidence that I infact know how to use it. Coupled with the need for an intranet file server application, I decided to make an Ajax version of a Server File Browser.

Initial Screen Using the Sarissa ajax library, this handy application only has a page weight of 71kb! Directory listings are limited to 30 files/folders per page, so the ajax requests are quite quick. Additionally, the application has been tested on Firefox and IE 6 only. Please leave me a comment if you have bugs with other browsers.

All shared files can be downloaded, and are force saved. Meaning that you can even share your PHP source files, without letting them be compiled first.

Application Configuration

After downloading the application, unzip the contents to a directory on your webserver. This application has been designed for a host where the php document root is the root path of the application. So, it cannot work under a sub-directory of a domain or host name. You may want to look into sub-domains if this affects you.

The application requires no database (although may do so in future, to log downloads etc). There is only one configuration file, config.inc.php. In this file there are two main settings:File Browsing

  1. Shares
    Paths to directories on the server. They do not have to exist as a sub-directory of the application, they can exist relatively or absolutely. So long as the web service has permissions to the directory, you can browse it. This is the biggest reason why I had to write my own application. Others on the net simply didn’t allow complete server browsing. You must be careful not to share anything crucial or anything that will compromise server security. Once a directory is shared, all sub-directories will also be shared.
  2. Blacklists
    You can exclude certain directory names, file names, and even file extensions from being viewed. I was also going to include something about hidden or system files aswell, but I got lazy :)

Apache vs Other Servers

Included in this package is a .htaccess file for Apache servers. It’s main directive is to prevent PHP’s short open tags. If you have an error with the htaccess file (as some servers will not allow php values in them) then you will have to make arrangements to prevent the short open tag in another way. The short open tag will affect the XML documents returned with the Ajax calls. This directive is now irrelevant in v1.1

Demo and Download

Changelog

  • 2006-09-15 v1.1, No need for short_open_tag anymore

Technorati: ajax, php, javascript, web 2.0


Share this Post:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • StumbleUpon
  • Slashdot
  1. written by Masoko September 7th, 2006 at 08:15 | #1

    This scripts is great! Ajax Rox


  2. written by Michael September 12th, 2006 at 22:40 | #2

    Hi,

    been trying to run it on my server it dun work :( , how do i install it.

    I have a directory called documents.

    Please Help :(


  3. written by jc September 13th, 2006 at 09:18 | #3

    How exactly doesn’t it work? Does the page load correctly, but the loading graphic hangs when you select a share?


  4. written by CJ September 15th, 2006 at 05:14 | #4

    It loads correctly on my linux server however hangs when you select a share?

    Is this only for windows file systems??


  5. written by jc September 15th, 2006 at 09:11 | #5

    Not at all. The demo hosted here is running on Linux with php 4.4.3.

    I’ve also tested it with php 5 and IE7 RC1 with no troubles. If the share folder didn’t exist, or couldn’t be found you would be notified with a message box. The only way the hanging should occur, is if there was an error with the XML data that gets returned. And the number one error there is the PHP Short Tags problem.

    I’ve fixed up a bit of the code that requires PHP short tags to be off, and now it doesn’t matter. The new version (1.1) is available from the link above.

    If the application still hangs on the waiting screen, try entering this in a new window:
    http://host/_ajax.php?share=1
    and if there is a problem with the XML return data, you’ll see it there. If not, you’ll see a well formed XML document.


  6. written by CJ September 15th, 2006 at 10:02 | #6

    Thanks for the quick fix! I’ll try it out….


  7. written by CJ September 15th, 2006 at 21:59 | #7

    Works! Great Ajax Script!


  8. written by Michael September 19th, 2006 at 20:45 | #8

    Hey,

    Thank you for the script it works great now :) , thanks for all the help :)


  9. written by Troy Jones September 23rd, 2006 at 19:12 | #9

    can it show the number of times a file has been downloaded next to the file size?


  10. written by jc September 25th, 2006 at 09:10 | #10

    Not without a database, or xml, or text file storage system. The trouble with logging downloads, is that files may be deleted on the filesystem, and the records of their download would still be in the database. So you’d have to execute a cleanup script once in a while so you only have relevant data. Assuming that’s ok, you would next have to log downloads, and compare the existing records by a md5 or similar, no 2 files are under the one record in the database. It’s some tricky stuff, and something I’d like to do, and probably will. When that time comes, I’ll re-release the script under something else, and may include an admin part so you could delete and upload files too.

    The question is, what should the new script be called?


  11. written by Michael September 26th, 2006 at 17:35 | #11

    Researched my way into dynamically adding a Directory List on the Left nav :D. here is the code

    $shares = array();
    //copy one of these array difinitions and modify.

    $dir = “../dirname/”;

    if ($handle = opendir($dir)) {

    while (false !== ($file = readdir($handle)))
    {
    $fileext = substr(strrchr($file, “.”), 1);
    if($file!=”" && $file!=”..” && $fileext==”" && $file!=”.”)
    {

    $shares[] = array(
    ‘name’=>$file,
    ‘title’=>$file,
    ‘path’=>’../dirname/’.$file
    );
    }
    }
    closedir($handle);
    }

    What do you think ??


  12. written by jc September 27th, 2006 at 09:16 | #12

    Very good, it’s one way you could go about it. When in the while loop though, I would add another check so that you are sure you are listing directories and not files aswell (incase someone copies a file there by accident). try:

    if (is_dir($dir.$file)) {
    //is a directory, add to shares array here.
    }


  13. written by wingfai September 28th, 2006 at 06:36 | #13

    Is it any way to amend the code to work on Chinese character on windows system ? Cause if encounter file name with Chinese character, it become wierd. Thks.


  14. written by jc September 28th, 2006 at 09:19 | #14

    I have no idea how to deal with chinese characters… or any non-ascii stuff. sorry


  15. written by Michael October 3rd, 2006 at 02:14 | #15

    Hi,

    We get a mouse over on the left nav, how do i disable that :( which says javascript void something :(


  16. written by jc October 3rd, 2006 at 09:27 | #16

    What browser, in what operating system are you using? And, are you getting the error when you view http://ajaxfb.jc21.com/ ?

    I’ve tested that site on IE 6 and 7 and Firefox on Windows XP, with no errors.

    I think I know what it could be, but I want to be sure first.

    If you are using a different combination of software, can you give me as much information about the error as possible. Thanks.


  17. written by volkan October 10th, 2006 at 10:11 | #17

    how do i or can i add restricted access /users to it?


  18. written by jc October 10th, 2006 at 10:36 | #18

    Using this code, you could apply a htaccess restriction to the page, but I’ll give you some inside info. I’m currently working on an improved edition of this, hopefully encompassing all the requests so far. Some major features would be:

    * A database to store settings, statistics. With a self install script
    * Anonymous and named user accounts with permissions per user, per share
    * Administration section - no need to edit config files.
    * Permissions for shares: View, Download, Delete, Upload

    I’d say I’m 30% complete with this new software, and I can’t give a release date. But to prove I am doing it, here’s a screenshot of the admin: http://blog.jc21.com/wp-content/screenshots/afb_demo.jpg

    I’m still struggling with a nifty application name…


  19. written by morningkarma October 11th, 2006 at 22:18 | #19

    Great script with very nice visuals. However it has some bugs. For example download doesn’t start if the filename comtains an ‘ (apostrophe).


  20. written by morningkarma October 11th, 2006 at 22:21 | #20

    Oh yes, and internationalization isn’t supported. With ISO-8859-2 (which doen’t differ much from standard English charset), the script fails. But, after all, this is a great work and I’m badly waiting the next version :)


  21. written by grimsy October 19th, 2006 at 11:34 | #21

    Nice app - and I like Michael’s dynamic folder view on the left.
    What would be nice is to have the option of a tree view on the left, so that each time you enter a folder, the nav tree is updated with the new folders.
    looking forward to the new version :)


  22. written by bprof October 22nd, 2006 at 06:08 | #22

    This is a great tool, I tried the demo and its WOW. But I tried to use it locally and I got this:

    http://img520.imageshack.us/img520/6244/filebrowserzd2.jpg

    Could you please help me fix it?


  23. written by bobdow November 9th, 2006 at 10:15 | #23

    is there any way to add thumnail support in a grid?


  24. written by Manuel Castelo Branco November 24th, 2006 at 23:39 | #24

    I´m Portuguese (Lisbon) , but now i live in Brazil (Itumbiara).
    Congratulation for your Script AJAX FileBrowser, it´s the best scripts that i see .
    Thank you for the script it works great.
    When i found the Portuguese Language ?
    Can i translate the script for the portuguese lang. ?


  25. written by jc November 27th, 2006 at 09:30 | #25

    When I introduce Language Support, perhaps you can contribute your own language file. As the Christmas holidays get closer though, I won’t have much time at all to spend on this project…


  26. written by Victor December 12th, 2006 at 14:41 | #26

    Hey JC,

    I’ve commented about previewing files before, and constantly check for sweet updates. I was just finishing up fantasy football with espn, and thought about roll over type of image preview like espn does. Images could roll over as you roll over the file links. That would be pretty slick. Anyway, just a thought.

    Thanks,
    Victor


  27. written by jc December 12th, 2006 at 14:49 | #27

    I’ve thought about that too. I think I’ve seen it in another file manager app before.


  28. written by btkk December 24th, 2006 at 15:36 | #28

    thanks for your great code.

    After successful installation, I can’t not login with the user and password I created before (The user and password are both correct, I can see it in my Database).

    Do you have any idea?


  29. written by jc December 25th, 2006 at 23:04 | #29

    try revisiting the site after closing the browser. the link supplied in the installation seems to be incorrect.


  30. written by G Tibi March 20th, 2008 at 18:46 | #30

    I have little problem. I can’t logon i insert my user/pass it’s loading a little bit and trows me back why ???


  31. written by Mike March 27th, 2008 at 02:44 | #31

    Same problem here as btkk and G Tibi. I installed it but cannot login.


  32. written by basavaraj March 27th, 2008 at 20:28 | #32

    Hi,

    I am not able to download the zip from the given link…

    http://blog.jc21.com/2006-08-21/php-ajax-file-browser/
    Let me know the correct link for downloading..

    Thanks in advance..


  33. written by basavaraj March 27th, 2008 at 20:30 | #33


  34. written by Dave October 2nd, 2008 at 07:08 | #34

    Hi, can your script show the contents of a subdirectory as well. I need a script that can be activated from a flyout menu so in other words, set the path to the parent directory in the menu and when the user activates the menu, the file browser would show a list of all files, in this case PDF files in the parent directory, as well as files in the subdirectory and allow them to be opened or downloaded.

    Thanks

    Dave