PHP File Tree

A PHP function that generates a valid, XHTML nested list of the specified directory. Includes a JavaScript extension that makes the entire list expand and collapse dynamically.

Overview

PHP File Tree is a PHP function that generates a valid, XHTML nested list of the specified directory. The script includes a JavaScript extension that makes the entire list expand and collapse dynamically.

Features

Compatibility

The PHP File Tree JavaScript extension is known to work in the following browsers, but expected to work in most others that support JavaScript, too:

Demo

Download

Download the current version of PHP File Tree.

Usage

Generating a File Tree

A call to the php_file_tree() function will return a string containing the XHTML code of the specified directory. To output it directly to the page, precede the function call with an echo statement:

echo php_file_tree(...);

Filter by Extension

You can limit the types of files that will be displayed by specifying an array containing a list of file extensions to allow:

$allowed = array("gif", "jpg", "jpeg", "png");

Passing $allowed as the $extensions parameter will return a list of directories and only show image files of the respective types.

Feedback

Use $return_link to specify the action you want done when the user clicks on a file name. Use [link] as the placeholder for the filename. For example,

php_file_tree("your_dir/", "http://example.com/?url=[link]");

would send the user to http://example.com/?url=filename.ext. This is highly extendable, considering you could even use javascript to handle the clicks:

php_file_tree("your_dir/", "javascript:alert('You clicked on [link]');");

Making the List Expand/Collapse Dynamically

Classic Method

Include php_file_tree.js into the head section of the appropriate page(s) as shown below:

<script src="php_file_tree.js" type="text/javascript"></script>

All file trees generated by PHP File Tree will automatically collapse to the top level (as specified by $directory) and become dynamic. You can have more than one file tree functioning on one page — simply create another using php_file_tree().

jQuery Method

If you happen to be using the jQuery libary, you can add the same functionality as shown above with a lot less code. You’ll also get the famous jQuery animations for showing and hiding tree branches, which improves usability and looks a lot nicer.

To use jQuery with PHP File Tree, make sure you are already including the jQuery library (if you don’t have it, you can get it on the jQuery download page) and then include php_file_tree_jquery.js.

<script src="jquery.js" type="text/javascript"></script>
<script src="php_file_tree_jquery.js" type="text/javascript"></script>

Depending on the version of jQuery you download and whether or not you get the compresses/uncompressed version, the name of jquery.js will vary. For example, jQuery 1.2 compressed will be called jquery-1.2.pack.js while the uncompressed version will be called jquery-1.2.js. Also, if you are already including the library you do not need to include it again.

Customizing the Appearance of the File Tree

The list can be customized completely using CSS and includes a default theme to aid in customization. Specific file types can be styled based on extension, making the file tree appear more like a standard file browser on your operating system. See default.css to get started.

Comments

Very nice work!

Amazing.

#1 Leo on Jun 27th, 2007

Cory,

Great work and beautifully styled. I'll get my head around how to deal with the links when clicked and put it into an application I am building. Thank you for making this available.

John G

#2 John Greenbury on Jun 27th, 2007

Adding a few bits as I go:

php_file_tree($_SERVER['DOCUMENT_ROOT']."/Example/", "...

will display all folders and files under the Example folder.

#3 John Greenbury on Jun 27th, 2007

Found that the window.onload event in the javascript file causes conflict with any existing body onload events causing the tree toggle not to function. Tree not collapsed when the page loads.

The solution seems to be to removed the window onload event (last line in js file) and place the following in body onload along with any others - possible making it the first event.

<body onload="init_php_file_tree();[other functions]">

#4 John Greenbury on Jun 28th, 2007

John, you're right...it's worth mentioning that you can't have more than one window.onload event on the same page. Scripting multiple functions inline works, but if you prefer to use unobtrusive code, create a separate function [i.e. init() or loadRoutine()] and assign it to the window.onload event. That method is a little cleaner and much easier to maintain :)

#5 Cory S.N. LaViska on Jun 28th, 2007

Can the script call the link like index.php?c=16 store in database?

#6 zeezan on Jul 10th, 2007

Is it possible to change the size of the indent for the new level of files, when a directory is clicked?
I've got to get this great-looking tree into a rather small box you see :)

#7 Jorn on Jul 13th, 2007

Nevermind, got it already.

Nevertheless, this tree view really is amazing, great work!

#8 Jorn on Jul 13th, 2007

very nice code. thanks a lot.... it worked for me

#9 ravish on Aug 14th, 2007

Help... I'm a noob: where do you specify the directory it is using? I figured there would be a spot where the variables got declared, but if there is I missed it :(

Other than that, really cool lil bugger. I'm just slow apparently.

Thanks in advance

#10 bob on Aug 20th, 2007

Freakin' awesome!
I spent days and days trying to make this. Then I stumbled across your site. You saved me a ton of time and yours is so much better than I could ever hope to cook up.

kudos!
Adam

#11 Adam Smasher on Sep 12th, 2007

BOB:
Where you have this line:
echo php_file_tree($_SERVER['DOCUMENT_ROOT'], "http://www.yoursite.com/yourdirectory/?file=[link]/";, $allowed_extensions);

Change it to:
echo php_file_tree("yourdirectory/", "http://www.yoursite.com/yourdirectory/?file=[link]/";, $allowed_extensions);

#12 Tony on Sep 13th, 2007

You can fix the window.onload problem by replacing the last line of the .js file with:

var cOnload=window.onload;
window.onload=function(){
cOnload();
init_php_file_tree();
}

#13 Dustin on Sep 15th, 2007

Actually, you may want to do it like this... 'cause firefox can be a booger if window.onload wasn't already defined.

You can fix the window.onload problem by replacing the last line of the .js file with:

var cOnload=window.onload;
window.onload=function(){
cOnload;
init_php_file_tree();
}

#14 Dustin on Sep 16th, 2007

I just added a new JavaScript file that you can use in conjunction with the jQuery library which, in my opinion, is a thousand times better than any conventional JavaScript method.

The code is shorter, it's cross-browser compatible, it's still accessible to users without JavaScript, and it looks nicer when it expands and contracts :)

#15 Cory S.N. LaViska on Sep 16th, 2007

WOW this is Fantastic!

Great script.
this was exact;y what i was looking for, im buildign a CMS and was trying to get a file editor done, and with this script its just easy! i basically done it within 2 minutes because of this script i only have ot gte some code to save it and that is my file system basically done and dusted :)

Great job top notch!

I should ask, what kind of license is this udner? i dont want to get into trouble if i want to sell/redistribute my CMS once it is done.

#16 Dan on Sep 20th, 2007

Thanks, I'm going to play with it. Lets see if I can pass parameters on a click.

#17 Cogmios on Sep 22nd, 2007

Hi, awsome script!!

I happened to run this code on a server that basically had all php warnings turned on. I got these two notices:

Undefined variable: php_file_tree in php_file_tree.php on line 73.

AND

Undefined variable: code in php_file_tree.php on line 24.

The first notice is caused by having an empty directory. The line "if( count($file) > 2 )" will cause all of the code to be skipped when the directory is empty. That causes the function to return and non existant variable. It seems to be fixed if you put $php_file_tree = ""; before the if statement.

The second notice is due to this code:

$code .= php_file_tree_dir($directory, $return_link, $extensions);

Line 24 is the first use of the $code variable so doing a .= seems to cause the problem.

These notices obviously dont affect the functionality but since they were a simple fix I thought I would go ahead and tell you about them.

#18 Killer-D on Oct 2nd, 2007

Thanks for this great script!!

I am not a php freak so where exactly do i have to add this "Feedback" line when i want that the files open when i click on them:

php_file_tree("your_dir/", "http://example.com/?url=[link]";);

Thanks a lot!

#19 Steffi on Oct 4th, 2007

I noticed you are using urlencode() in php_file_tree.php to encode the file names before they are appended to the link.

If the file names have spaces in them then urlencode() will change those spaces to a +. When I tried this in FireFox and IE neither of them liked the + in the links.

If you replace the urlencode() with rawurlencode() it will change the spaces to %20 which the browsers accept.

#20 Killer-D on Oct 4th, 2007

Hello,
thx for this nice script!
It would be nice, if you can post a hint for collapsing an expanding the whole tree!

greetz from germany
summsel

#21 summsel on Oct 8th, 2007

Looking for a method to change my method of menu building I found your php script. I don't know nothing about php and javascript. Nevertheless from my experience of programming long time ago ( Pascal, Algol) I could see that your code is written very elegant. So I gave it a try and was amased that I get it working in some minutes.
But if I want to use it for site navigation I need some features more: exposing the name of the files without the file extension and expanding the menu with no or hardly no outdent.
Well it's just a hint. But I think with such possibilities it can be used for a lot of different sites as navigation bar. The main advantage: the menu reflects the site construction and you don't have to create the links individualy.

#22 puntopunto on Oct 9th, 2007

Killer-D: Thanks for the tips, I'll make the changes in a revision soon :)

puntopunto: You can change the indentation using CSS. If you want to modify the name of the file being displayed, just hack the code :) Most people won't want to do this so adding extras like that would cause too much overhead for what the script is intended for: a basic framework for whatever you want to use it for :)

#23 Cory S.N. LaViska on Oct 9th, 2007

Answer to Killer-D and Cory S.N. LaViska
I'm waiting for the update, I desagree with Cory: there must be a lot of people willing to use it as an advanced menu bar.
Hacking the code is several bridges too far for me.
And everything I tried to do with the css file won't let disappear the listlike expanding. Maybe you can give me a hint.

#24 puntopunto on Oct 10th, 2007

very simple question...
how do you get it to open whatever file you click on?
cheers

#25 nick on Nov 12th, 2007

I really love it :-)

How about cookies to remember folder state ?

thank you

#26 feha on Nov 22nd, 2007

echo php_file_tree("../../News/Latest_News/", "http://www.mysite.com/News/Latest_News/?file=[link]/";;, $allowed_extensions);
doesn't work for me. Does anyone have any more detailed info on how to link to a specific folder that is not the same folder this script resides in?

#27 Keith on Nov 28th, 2007


Can anyone tell me why "php_file_tree("News/Latest_News/", "http://mysite.com/News/Latest_News/?url=[link]");"; doesn't work?
In other words why does the tree not work when I specify a specific folder?

#28 Keith on Dec 4th, 2007

this is pretty cool but it's not customizable for PHP beginners who want to show the contents of a specified folder. Thanks anyway!

#29 Keith on Dec 4th, 2007

First, very nice work!

I have a simple question regarding this script...
It works like a charm if I have a small bunch of files and folders, but if I specify the file tree to a directory that contains at least 2000k files and folders, the script dies after about 30 seconds and nothing shows up on the website.

Do you have any clue to workaround this?

Thanks!

#30 Viktor on Dec 16th, 2007

Viktor: see http://us2.php.net/set_time_limit

#31 Cory S.N. LaViska on Dec 16th, 2007

Ah yes, I have tried to modified php.ini and changed the max_execution_time value. After X seconds I got this instead:

[Sun Dec 16 19:53:48 2007] [error] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 71764505 bytes) in php_file_tree.php on line 60.

The problem here is that my directory is too big for this script to handle and get a directory tree.

I think the best should be to fix that without having to make read all the directories/files at once, instead take it step by step? Otherwise it runs out of memory...
What do you think about that?

I like your script and it should be greatful if it could works like a charm even with big archives:)

#32 Viktor on Dec 16th, 2007

Great I figured out how to link to a specific folder of PDFs on the webserver...
// This links the user to http://example.com/?file=filename.ext and only shows pdf files
$allowed_extensions = array("pdf");
echo php_file_tree($_SERVER['DOCUMENT_ROOT']."/News/Latest_News/", "http://www.mysite.com/?file=[link]/";, $allowed_extensions);

...now trying to figure out how to open the file when clicked on because presently when clicked it tries to open a file at this address...
http://www.example.com/?file=C:\Inetpub\wwwroot\example/News/Latest_News/February_2007.pdf/

#33 Keith on Dec 19th, 2007

I like the script, but was wondering if it was possible to read the directories on your computer from then a server????

#34 Dave on Jan 7th, 2008

Hello, how to run this script on local computer?
A wonna make list docks. pipul on my group.

#35 Tomek on Jan 8th, 2008

Hi all,
i have tried to add to CSS style following code to highlight selected link.This work, but after 1 second the active/clicked link change color back to the same color as other links. Can you help me ?
.php-file-tree A:active {
color: #FF0000;
}

#36 Milos Sula on Jan 14th, 2008

Hi all,
i have tried to add to CSS style following code to highlight selected link.This work, but after 1 second the active/clicked link change color back to the same color as other links. Can you help me ?
.php-file-tree A:active {
color: #FF0000;
}

#37 Milos Sula on Jan 14th, 2008

Thanks a lot for this... it's amazing! Nicely styled and works like a charm! You're the greatest!

#38 Rem on Jan 24th, 2008

it's a very nice script, but i have only one problem i can't solved: houw can i get rid of the extensions, for example: when published in a folder funplace.wmv i don't want to see the .wmv.... Can somebody help me? Thankx-a-lot, Thomas

#39 Thomass on Feb 18th, 2008

Very nice solution.
Clean and efficient, I'm looking forward to using it in a current project.
Thanks for taking the time to create and share.

#40 mike foskett on Feb 19th, 2008

Thomass ,

in your php_file_tree.php look for a line in the if statement that says this:

<code>htmlspecialchars($this_file) </code>

and change it to

<code>htmlspecialchars(substr_replace($this_file,"",-4))</code>

assuming that all your file extensions are 3 letters and the period (.jpg, .pdf, .wmv, etc) it will remove the last 4 charachters from the thus the period and the 3 trailing letters of the extension.

#41 Alan on Feb 19th, 2008

Just a simple way to display the homedir of the Logged User Only : (this one is for a webdav access userdir set-up)
You also have to disallow the non logged users to the script....
//
echo php_file_tree($_SERVER['DOCUMENT_ROOT'].'/Webdav/'.$_SERVER['PHP_AUTH_USER'], "../getFile.php?download=[link]");
//
I would be interrested in different CSS for this great script

#42 ladislav on Feb 27th, 2008

Is there a way to list up from the doc root?

- Shelon Padmore

#43 Shelon Padmore on Mar 7th, 2008

Hi! greate script. I am not a PHP freak, but can somebody help me : I need the relative path+filename clicked in a PHP variable... something like : $clicked=php_file_tree("./", "[link]");

.. since I am not a PHP freak, and I have to modify a script I have no idea how to realise this....

Anyone hwo can help ?

#44 Erik on Mar 8th, 2008

Hi,

The script is great, indeed. I'm wandering if I can use it in my projects. What are the license conditions?

thanks.

#45 Cezar on Mar 8th, 2008

Cory, you are a god!

#46 Levi Lewis on Mar 14th, 2008

Is it possible to have the script ignore certain sub-folders, say those matching a naming convention, or entries in an array (similar to the way you've restricted extensions)?

#47 Thomaas on Mar 19th, 2008

...Sorry to double post, but I've discovered the solution:
In php_file_tree.php, there is a conditional statement that looks like the following:
//
if( $this_file != "." && $this_file != "..") {
//
Change it to:
//
if( $this_file != "." && $this_file != ".."&& !in_array($this_file, $hiddendirs)) {
//
Create an array containing the directory names before the conditional statement, and outside the 'foreach' loop. Example:
//
$php_file_tree .= ">";
$hiddendirs = array('personal','private','docs');
foreach( $file as $this_file ) {
if( $this_file != "." && $this_file != ".." && !in_array($this_file, $hiddendirs)) {
//
I pulled the '$hiddendirs' variable completely outside the function and passed it in like the '$extensions' variable the script came with, and it works like a charm.
Thanks for developing such neat script. :)
-Thomaas

#48 Thomaas on Mar 19th, 2008

This is fantastic, however I will try to modify it so it uses Ajax instead of reading all directories first. This should help fix the large directory problem time-out thingy. It will be a little slower, but should also take up less resources.

I think you did a great job - very neat and actually looks good too. Thank you very much for sharing it.

#49 Joe on Mar 19th, 2008

Hi,

always when i want to follow a link like
http://www.larissa.hummel-web.at/?url=/home/.sites/99/site67/web/larissa/adminseite.html

i just jump back to the startscreen of http://www.larissa.hummel-web.at

can't figure out, php is not my thing, but i want to use this great php script :)

hope for help

thanks
chris

#50 Chris on Mar 21st, 2008

Hi again.

another question after playing around.
How can i set that the root Dir begins at /home/.sites/99/site67/web ?

when i remove $directoy frpm php_file_tree.php it the link works now on files in same directory, but not on subs, because the link then is generated as
http://www.larissa.hummel-web.at/?url=adminseite.html

otherwise as above, where he finds nothing, because he searches the file in
..el-web.at/home/.sites/99/site67/web/larissa/adminseite.html

thnx

#51 Chris on Mar 21st, 2008

already found a solution for me :)

in demo_classis i just make a chdir to the DocRoot
and an entry like echo php_file_tree('./', "javascript:void(window.open('[link]' .....

then the url is generated with the full Path from DOCUMENT_ROOT and begins with /index.html to next Level /EXAMPLE/index.html etc.

when i finished with the site, i post it, that u can see, what i made of it.

thanks for that great script. Also good for learning :)

chri

#52 Chris on Mar 21st, 2008

Thanks for the script - it is nice :) - I'm a windows user running php5.2.5 and new to php and javascript - can you tell me how to browse the root of a drive. For example, can browse C:\WINNT but not C:\ and also how can I make the directories browsed case insensitive - For example I can browse C:\Program Files but not C:\program files and finally how do I set the file clicked to a variable, echo php_file_tree($chris, "javascript:alert('You clicked on [link]');"); works ok but echo php_file_tree($chris, "<?php $clickedfile = [link]; ?>"); and echo php_file_tree($chris, " $clickedfile = [link]; "); did not - well I thought, in my ignorance it was worth a go :) - as I said I am just starting out with php
chris

#53 CHRIS on Mar 22nd, 2008

Hi,

so thats what i made of it :)
http://www.larissa.hummel-web.at/fotos/browse_frameset.htm

thx
chris

#54 Chris on Mar 23rd, 2008

Chris, though I can't comment on your root Windows directory browsing issues (other than to say I have a feeling it's a Windows security thing, as I've been able to successfully navigate a linux server directory structure), I can tell you that you're not going to be able to assign the value the user clicks on to a PHP variable. In the following lines:
//
echo php_file_tree($chris, "<?php $clickedfile = [link]; ?>");
//
Or
//
echo php_file_tree($chris, " $clickedfile = [link]; ");
//
It would seem you were trying to assign what the user clicked on to a PHP variable, which isn't possible at this point on the page. PHP is executed before the page loads. You can, however, 'process' the user's selection with Javascript:
//
/* $chris should be your directory, but remember that '\' may be treated as an escape character */
echo php_file_tree($chris, "javascript:myScript[link]");
//
Now write a javascript function (called myScript to do what you wish with the value the user clicks on (which will be a directory path). There are quite a few javascript tutorials and scripts on the web that can be combined to do whatever you're looking to do.
-Thomaas

#55 Thomaas on Mar 26th, 2008

hello, did anybody solve the issue of dealing with large directories and sub directories. the script is nice but reads all dirs and sub dirs and files inside first.... therefore it takes some time when reading such jumbo directories? any clues?

#56 Marco on Apr 6th, 2008

Marco, see my jQuery File Tree at http://abeautifulsite.net/notebook.php?article=58

#57 Cory S.N. LaViska on Apr 6th, 2008

Your application is great. But i has a small problem that i want create(delete) a file(folder) . And browser will change automatic"OLD TREE FILES" to "NEW TREE FILES" (or call it is automatic UPDATE TREE ). How to do that ?
Thanks
MinhTho

#58 Minh Tho on Apr 9th, 2008

Hello. This looks awesome. I uploaded the folder to my server and used the classic demo and it shows all the files and folders on my server. No problem. I also got it to how only specified file types. In my case, PDF files...No problem. But I am having trouble with the specifed folder. I have tried the following:


echo php_file_tree("documents", "http://example.com/?file=[link]/";, $allowed_extensions);

And...

echo php_file_tree($_SERVER['DOCUMENT_ROOT'], "/documents/", "http://example.com/?file=[link]/";, $allowed_extensions);

Neither of these work. What am I doing wrong?

Thank you!

#59 Jerry on Apr 12th, 2008

I tried this also. I get a message about no such file or directory, but it is there.

echo php_file_tree("documents/", "http://example.com/?file=[link]/";;, $allowed_extensions);

By the way...I am just editing the default demo_classic.php file.

#60 Jerry on Apr 12th, 2008

Ok..got this part working..but now how to you make it open a PDF file when it is clicked on?

echo php_file_tree($_SERVER['DOCUMENT_ROOT']."/documents/", "http://www.mysite.com/?url=[link]";, $allowed_extensions);

Thanks..Jerry

#61 Jerry on Apr 12th, 2008

Ok...this works for me when only showing PDF files and allows me to open them when clicked. Also..you have to be careful copying and pasting from this (your) website. A semi-colon appears at the end of pasted links...right before the coma before $allowed_extensions);

This works for me..but watch that extra semi-colon.

// This links the user to http://example.com/?file=filename.ext and only shows PDF files
$allowed_extensions = array("pdf");
echo php_file_tree("../documents", "[link]", $allowed_extensions);

#62 Jerry on Apr 12th, 2008

Hi,

I am new to PHP, can anyone help me out. How do I make the script to open the particular file by clicking on it, as in normal directory browsing?

Thanks...

#63 Himanshu Singh on May 1st, 2008

I got a problem while trying the script as below at line 73. What is the possibility problem?


Notice: Undefined variable: php_file_tree in c:\program files\easyphp1-8\www\php_file_tree\php_file_tree.php on line 73

arg

#64 arg on May 6th, 2008

See example #1: http://us3.php.net/error-reporting

#65 Cory S.N. LaViska on May 7th, 2008

Hello
is it possible to customize this application in the way i would like? of course to pay you.

#66 George on May 8th, 2008

How can i split the files into 2 columms?

#67 George on May 8th, 2008

Ok... I'm relatively new to PHP and am having a few issues with the script. First of all, the site I'm trying to get this to run on is hosted on a Windows Server 2003 box with IIS 6.0. It's a protected site using LDAP authentication.

I drop the files in the root of the website and when I open demo_classic.php it will populate the directory listing very nicely. However, if I change it to the option to click on the file to open it the path it tries to open is the server's local path to the files on it's hard drive, "c:\Inetpub\mysite\nonsense.html" Is there a way to fix this.

Also, I would prefer to point this listing to a subdirectory. I have tried all the previously posted methods for this and each time I either get the root directory again, minus all files (only folders) or nothing at all.

Any help that can be thrown my way would be greatly appreciated.

#68 Louis on May 19th, 2008

Very, very nice menu you have here. It's also not too dense to be nicely hackable for a non-php-ninja like myself, plays well in horrible nests of iframes and phpincludes, and the icons make for quite the bonus too.

I used it in my facebook ZX Spectrum app, hilariously loading zippd/raw spectrum files into a java emulator instead of calling the actual file into the browser.... check it out: http://slugbubble.com/zxspectrum/

...any chance of a future version with custom icons for specific items, instead of one icon per filetype?

#69 Tom Oldfield on May 30th, 2008

Is there a way to specify to display a certain directory, instead of all the folders in a site?

#70 JG on Jun 12th, 2008

JG - I believe the answer to your question can be found earlier in this thread - but I have put it below for you.

change the line "echo php_file_tree($_SERVER['DOCUMENT_ROOT']......"

so that the $_SERVER['DOCUMENT_ROOT'] part says "getcwd(),"

That will only retrieve the files in the current windows directory you are looking at rather than on the whole freaken site. another way to do this would be to just put "../", and that should do the same thing.

Lous - change the line of code I was just talking about above to:

echo php_file_tree("../startingWithFolderNameWhereThisFileIsLocated-ListTheDirectoryPathToSubfolderYouWantDisplayed", "[link]", $allowed_extensions);

Leave the word [link] alone, and do not change the last bit (unless it is to remove it b/c you do not want to restrict viewing to only certain files).

Now a question of my own:

This is beautiful code, but when I use it in explorer, once the folder expands, the icon moves until it is centered vertically with the open sub-directory. Anyone know how to get the icon to stay put? It works fine in firefox.

Cheers -
Shannon

#71 Shan on Jun 19th, 2008

Hi,thank you.It is working nice by GTR

#72 Thiyagarajan G on Jun 20th, 2008

Can anyone tell me how I can get the indent to work? and also once the tree is displayed on my page and I click on a file how can I get it to brings up the download the file box.

Thanks I am really new to PHP

#73 matt jennings on Jun 30th, 2008

OK all i need now is for the indent to work.

#74 matt jennings on Jun 30th, 2008

OK again adjusted the indent with padding in the CSS.
Can anyone tell me how to adjust the sort order of the folders to be sorted by date rather than alphabetical

#75 matt jennings on Jun 30th, 2008

excellent script . . . nice and clean and easy to integrate into existing code.

Q: Why would, when click on a file to open, would I get a 'sorry you don't have access . . . ." I've check the permissions and they seem to be good.

thanks again for the hard work . . .

#76 James on Jul 7th, 2008

Hi, great work! I was wondering if there's a way to pass parameters that would expand a specific tree.

Thanks!

#77 El Duce on Jul 9th, 2008

Hi Thats a great work...and very easy to understand. But this Tree Structure is not working in Firefox 3.0. Can anyone give information regarding this Issue

#78 Abishaik on Jul 10th, 2008

This is not working good in Mozilla.
All the links get expanded in Mozilla
before I click particulary any link from
the tree.

#79 Anilkumar on Jul 10th, 2008

@Abishaik, Anilkumar: first I've heard of any problems with this in Firefox. Works fine on my 2.0 and 3.0 installations.

#80 Cory S.N. LaViska on Jul 11th, 2008

thank you very much for sharing your knowledge.

#81 Saeed on Jul 12th, 2008

First of all thanks for your reply.
Let me explain my problem clearly.
Folder Structure of RootFolder is as follows(This is just for explanation)
RootFolder
---- subfolder1
--subfolder1.1
-- a.txt
-- b.txt
---- subfolder2
-- subfolder2.1
-- d.txt
-- e.txt

echo php_file_tree(RootFolder,somepage)
We are including the output of this in
td tag of a table tag.

In IE : a.txt,b.txt get displayed only when I click subfolder1.1.
IE output:
RootFolder:
subfolder1
subfolder2

In Mozilla: When I include output of above echo statement, Rootfolder, the subfolders and files with in that are getting displayed as follows:
RootFolder
---- subfolder1
--subfolder1.1
-- a.txt
-- b.txt
---- subfolder2
-- subfolder2.1
-- d.txt
-- e.txt
I hope you understand our problem.
We are waiting for your valuable advice.

#82 Anil on Jul 13th, 2008

Hi... Thanks for your quick reply......
Let me explain you my problem.........

The Tree Structure is working fine in IE 6 and 7....
But coming to Firefox the problem is as below..

Actually i have embedded this Tree Structure under anImage(+) ... so, when i click on that Image the Tree Structure gets displayed.

This Tree Structure works fine in IE.....

But coming to firefox......
The folders and the Inner folders and the files present in the folders are getting displayed directly without clicking on any link in the Tree structure....

Hope you Understand the problem.....

Waiting for your reply..........


Thanks & Regards,
Abishaik

#83 Abishaik on Jul 13th, 2008

@Abishaik, Anilkumar: your problems sound similar. My first instinct is that you have another window.onload() somewhere in your other JavaScript code that is conflicting with the expand/collapse JS code included with the file tree. If so, you might want to consider using jQuery and $(document).ready().

Other than that, I can't seem to reproduce the problem :(

#84 Cory S.N. LaViska on Jul 14th, 2008

My problem is:
when the folder size is too big, there is a fatal error:"Maximum execution time of 100 seconds exceeded in php_file_tree.php".
It is impossible to wait 5 minutes to open the website page.

looking forward to your reply.
Thank you very much.

#85 Cherry on Jul 16th, 2008

@Cherry: there's really no way to avoid that...the script is obviously trying to process a LOT of directories and files in one shot. A better solution would be an AJAX-based file tree, that loads each directory only as they're requested.

Check out jQuery File Tree, which does just that: http://abeautifulsite.net/notebook/58

#86 Cory S.N. LaViska on Jul 16th, 2008

Ok, just about got this working how I need it too, would love to be able to set the icons for the folders based on their name, is this possible?

#87 Matt on Jul 17th, 2008

Thank you for the great program. I have on problem, however. When filenames have spaces in them, the links do not work. (A plus sign goes where the space was.) Can you help? Thank you.

#88 Natalie on Jul 17th, 2008

Thanks 4 this great code. but i m having a problem.

My problem is that whenever i wanna download a file it shows theres no file named (suppose file name "new file" then it will show "example.com/file/new+file" not available.

Those files creates this problem which files name have space.

But those file's name which don't have a space download successfully.

What will be the solution?How can i Download?

#89 zahid on Jul 18th, 2008

Hi, great work! I'm testing this and was wondering if there's a way to specify what can be expanded or callapsed in the lists. Any help would be greatly appreciated. Thanks!

#90 dinonet on Jul 23rd, 2008

Great !!! nice work, thanks for this code :)

#91 Kustan on Jul 23rd, 2008

How hard would it be to all checkboxes so yo can select multiple files?

#92 Jeff Gates on Jul 24th, 2008

Really a nice script!
I already used it in two projects.

Thanks for your work :)

#93 Matthias on Jul 29th, 2008

Hi can i reduce the size of the of the tree. what i mean to say is i am able to see the list of the folders and files using this php_file_tree($_SERVER['DOCUMENT_ROOT'], "javascript:alert('You clicked on [link]');");

can i reduce the gap between the list directoraires and files .let me give an example when i click on the tree these are the folders and files i am having in my directorary and the view will be like this.
-mydir
-newdir
-nextdir
- present.php
- next present.php

can i reduce the gap between the folder so that
-mydir
-newdir
-nextdir
- present.php
- next present.php
Any help would be greatly appreciated. Thanks!

#94 vinod on Jul 31st, 2008

hi the tree structrue it was not clear what i have given earlier. let me put the tree structure example which will display the following folders and files when i click the tree.

-mydir
-----newdir
----------nextdir
------------- present.php
------------- next present.php

can i reduce this size to
-mydir
--newdir
----nextdir
----- present.php
----- next present.php

#95 vinod on Aug 1st, 2008

@natalie @zahid:
in php_file_tree.cpp (line number 70) while listing files just replace $link with urldecode($link) in href tag and space problem should be solved. i am not sure if it will cause problems anywhere else.

#96 gimley on Aug 4th, 2008

First of all, this script is more than great!
But, unfortunality i've got a problem. i use this folder tree for mediafiles. i have more than 100+ mediafiles, and because of that the page loads very slow. I don't know how to fixed that. Does anyone?

#97 Thomass on Aug 14th, 2008

Hi All

Please help in customizing the look and feel of the tree like as in:
http://sugatabhar.freetzi.com/test1.html

Thanks
Sugata

#98 sugata on Aug 20th, 2008

Add a comment

Name*

Email*

Never, ever sold or spammed :)

Homepage

Comment*

Sorry, plain text only :(