Jul 25, 2008

Need Some Help In File Browser - listing all sub folders and files in them.

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

Need Some Help In File Browser - listing all sub folders and files in them.

apple
Hey
I want to create a very simple file browser, so that, it reads all the sub-folders which are places in a directory, and the files inside the sub-folders (It reads only files inside sub-folders and list them in simply. ) Also, it creates a directory (any name) inside each sub folder.
My Following code reads on the files inside the main directory, it does not read the files inside the sub-folders.. I appreciate any help.


CODE
<?
$path = "./";
$dir_handle = @opendir($path) or die("Unable to open $path");
while ($file = readdir($dir_handle)) {
if($file == "." || $file == ".." || $file == "index.php" )
continue;
echo "<a href=\"$file\">$file</a><br />";
}
closedir($dir_handle);
?>

Reply

galexcd
If I am understanding you correctly, you want it so when you click on a folder, it shows you the files in that directory? If so, are you changing the path when you travel inside the subfolders? If not, then that would be your problem, but if you want to show files under that dir in the same page I would recommend recursion. Something like this:

CODE
<?
function display($path){
$dir_handle = @opendir($path) or die("Unable to open $path");
while ($file = readdir($dir_handle)) {
if($file == "." || $file == ".." || $file == "index.php" )
continue;
echo "<a href=\"$path$file\">$file</a><br />";
if(is_dir($path.$file)){
echo"<table><tr><td width='50'></td><td>";
display($path.$file."/");
echo"</td></tr></table>";
}
}
closedir($dir_handle);
}
display("./");
?>


This code was tested and works like a charm.

 

 

 


Reply

apple
Thanks for your help.. but this code displays all the files of sub-folders on the index page.. i want to display the sub-folder files when clicked on the sub-folder.
thanks.

Reply

jlhaslip
Then you will need to modify the output by building a menu from the results. Find a menu which 'opens' the sub-folder list when it is clicked. Dynamicdrive.com likely has one for that.

Reply

galexcd
QUOTE(apple @ Mar 26 2008, 02:16 PM) *
Thanks for your help.. but this code displays all the files of sub-folders on the index page.. i want to display the sub-folder files when clicked on the sub-folder.
thanks.



I know, you weren't very clear in your initial post so I provide two solutions.

QUOTE
If I am understanding you correctly, you want it so when you click on a folder, it shows you the files in that directory? If so, are you changing the path when you travel inside the subfolders? If not, then that would be your problem, but if you want to show files under that dir in the same page I would recommend recursion.


There would be two different ways of doing this. One would be just to send the path over a get modifier, but you may not want that becasue you want to be in the directory that it shows you? That may not have been too clear. Here is a basic explanation of the two solutions:

SOLUTION 1:
you go to your website, let's say its at www.example.com and you see your file browser
Lets say you have 3 directories under your root directory called "images", "stuff", and "more stuff".

So when you view your site at www.example.com you see 3 links titled "images", "stuff", and "more stuff". And if you were to click on one of the links it actually doesn't go to that directory, but only sends the data of which one you clicked on via the get variable to the same page, so clicking on "images" would bring you to www.example.com/?dir=images rather than www.example.com/images, but you would be able to view the files in that directory. If this solution works for you here would be the code to do it:

CODE
<?
$path=isset($_GET['dir'])?$dir:"./";
$dir_handle = @opendir($path) or die("Unable to open $path");
while ($file = readdir($dir_handle)) {
if($file == "." || $file == ".." || $file == "index.php" )
continue;
echo "<a href=\"?dir=".$_GET['dir'].$file."/\">$file</a><br />";
}
closedir($dir_handle);
?>


SOLUTION 2:
If you want the file browser to show up on every page that doesn't have an index file on it, you can either go through the long process of adding a php file to every directory you want it in and change the $path variable to the current path but that is just tedious. There should be a way of setting directories that don't have index files to point to a certain php page, using htaccess?? Possibly? I'm not quite sure. I'm not too savvy with that file. If you can get it to point to a php file then you would just use your php code with one slight modification:

CODE
<?
$path = ".".dirname($_SERVER['PHP_SELF']);
$dir_handle = @opendir($path) or die("Unable to open $path");
while ($file = readdir($dir_handle)) {
if($file == "." || $file == ".." || $file == "index.php" )
continue;
echo "<a href=\"$file\">$file</a><br />";
}
closedir($dir_handle);
?>

Reply

apple
Thank you once again for your detailed explanation.. i really appreciate it.. your first solution is very nice.. but when i click on any subdirectory.. i get the message "Unable to open".. why it is unable to open the subdirectory

Reply

galexcd
QUOTE(apple @ Mar 27 2008, 02:37 AM) *
Thank you once again for your detailed explanation.. i really appreciate it.. your first solution is very nice.. but when i click on any subdirectory.. i get the message "Unable to open".. why it is unable to open the subdirectory



Copy and paste the address from the url bar when it says unable to open. There may have been an error in my code somewhere. I need to actually see this to help you figure out what is going on.

Reply

apple
okay..
Below, the file fb4.php contains your solution 1 code and is located in directory "fb" . there are many sub directories, the following adress appears after clicking on a subdirectory name "images".

http://localhost/test/fb/fb4.php?dir=images/

This page prints only this "Unable to open"...
it can not open any subdirectory.

Reply

jlhaslip
Umm... posting a test link to your localhost won't work for us.
Can you upload it to your site account, please, and re-post the link, thanks.

And, please confirm that there is an images directory under 'fb'.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : file, browser, listing, folders, files,

  1. How Can You Get Audio Files From Itunes Videos?
    (0)
  2. Japanese Browser Called Sleipnir
    (2)
    I came across this browser by a fluke chance when I was checking out articles at PC World, and from
    what I remember from the article this is a very big name browser in Japan and they wanted to expand
    it to the international market. What really caught my eye is that they want to get 5% of the
    international market in the browser wars in the next couple of years. To give a background story to
    this browser, it was developed in 2005 in both English and Japanese and after 3 years it gain some
    popularity in the international community and so now they are trying to enter thems....
  3. Naming Web Page Files
    Which way you like- MyPage.html or my-page.html or my_page.html (5)
    Everybody talks about meta tags, keywords, good title names and how they can increase page rankings,
    etc. But I was wondering whether the page name itself holds any value in indexing. Yes, I am
    talking about the web page file names (some-thing.html) NOT the one which you put in title tags. I
    am going to express my views and want to know what you think is correct. I have seen pages named in
    various ways like these: 1) my_web_page.html 2) DoYouLikeMyPage.html 3) hey-see-my-webpage.html (I
    think this way is more appropriate) 4) this.is.a.page.html (somewhat confusing) ....
  4. Audio Files?
    (3)
    I need some help. Is it possible to get audio files off of sites? Like IMEEM and YouTube. I know the
    whole http://www.file2hd.com thing. It doesn't always work though. Are there other ways? Is
    there a way people hack audio files off of sites? NOTE: I DO NOT WANT DO THIS! I merely want to
    know so that I can protect my sites from it. Thanks.....
  5. Jar Executable Files
    (1)
    I have been supplied with a digital log book for use this semester and it comes in the form of a
    .jar file and a .mdb file. I tried running it on my mac but it crashes every time but it seems to
    run perfectly on windows xp. Does anyone have any ideas why? I thought .jar files would be
    computable on any platform. ....
  6. Scroll Message On Top Of Your Browser..
    (3)
    Hello everyone, Some day I saw when I open one site to be at the top browser runs message.Can let
    someone help you about this, perhaps need some code would add.I need that I have on my future
    site.When again find one site that you notification look ... Thanks in advance, I ask for help...
    /sad.gif" style="vertical-align:middle" emoid=":(" border="0" alt="sad.gif" /> (sorry for bad
    english)....
  7. Internal File Transfer
    (5)
    Is there some kind of file transfer utility that can be used within the intranet for file
    transfers..? We have so much need for such an utility here in my work place.... The problem with
    what we are using is very big... we are basically using skype in my workplace and the problem with
    that is it happens with the internet... So whenever i transfer files via skype it occupies the
    bandwidth.... which is very bad since we have a limited bandwidth connection. So... What i require
    is a utility where the transfer happens within the network and not via the internet. So... if ....
  8. Best Browser To Desighn Your Site To
    not much of a question but more like a statement (9)
    well since i started web desighning i've always used internet explore (why?) well when i first
    tried FF2, i wasn't a "web-designer" then so i didn't care much about css and htlm stuff, i
    din't like it and one of the reason was beacause a couple of the sites i visited wasnt firefox
    compatible. but anyways recently i was desighning a site for this community. so like two weeks ago i
    downloaded FF3 for testing purposes. in IE the site looked great but what i found was that in
    firefox the site was horible, as bad as they could come. so since firefox was better....
  9. Making My Own Browser
    Uhm...need a name (6)
    I am currently developing my own Web Browser and I need a name for it /biggrin.gif"
    style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /> So if you got any good
    ideas please do post them /biggrin.gif" style="vertical-align:middle" emoid=":D" border="0"
    alt="biggrin.gif" />....
  10. Best Way To Transfer Files
    I just bought a laptop (6)
    Hi there guys, I just bought a brand new Dell Inspiron laptop for $729.99. It has a
    processing speed of 2.0ghz, 3GB RAM, and a 250gb hard drive. I'm really satisfied, especially
    with the wireless internet and the fact that I can carry my computer around with me, allowing you to
    use your computer in comfortable spots -- outside in the shade, on the train, or even in your bed
    where I'm using it write now as I type. If you didn't already guess, this is my first
    laptop. But I do have some issues. Does anyone happen to know an easy way to transfer some ....
  11. 1350 Great Free Logos (jpg + Psd)
    With both jpg and original psd files to edit (7)
    1350 Great Free Logos (With both jpg and psd files)
    http://rapidshare.com/files/126291346/1346...Great.Logos.zip This is a great collection of
    logos, they are already made logos which you can use like that or just use to create other logos, do
    what you want, they are free, they came from free websites that give this logos for free and lot
    more, but i just took the good ones mainly. There is also a small collection of 100 logos inside
    the compressed file, which you can use to insert those graphics in your logo/design/web design
    projects, do what you want with them ....
  12. Free Software For File Recovery
    RECUVA (3)
    Hi all, I was loking for a software to recover my lost files and I found this /biggrin.gif"
    style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /> And the best part is ,
    its free Recuva - File Recovery Recuva (pronounced "recover") is a freeware Windows utility to
    restore files that have been accidentally deleted from your computer. This includes files emptied
    from the Recycle bin as well as images and other files that have been deleted by user error from
    digital camera memory cards or MP3 players. It will even bring back files that have been d....
  13. Where Is The Bookmarks File Stored With Ff2?
    (4)
    My bookmarks are critical and lengthy. I'd like to save them to a flash drive, since my laptop
    is ancient and it's been acting up lately. I went into the FireFox folder, but couldn't find
    the bookmarks info anywhere. there's a bookmarks.html page, but it doesn't contain the
    actual bookmarks. Where does FF2 store the bookmarks? Or is there an easier way to copy and paste
    the bookmarks to another file? /huh.gif" style="vertical-align:middle" emoid=":huh:" border="0"
    alt="huh.gif" /> 2 poor 4 a sig ....
  14. Converting Audio Files In Vista
    how do you do it? (7)
    Ok, so I have some .wav files that I'd like converted into .mp3. I knew how to do it in XP, but
    I can't find windows audio converter in Vista....does vista even have that, or is it under a new
    name? Also, is it possible to convert video files, like .flv into .avi?....
  15. Firefox 3 Sucks - Time For Another Browser
    (48)
    No seriously, I've been using Firefox since 0.x releases. I loved it. Every release, despite
    having no huge features, was a great update. Version 3, however, totally messes everything up. Its
    default interface is ugly. And no Home button, really ??? (ps. I kno i can drag it back from the
    bookmarks toolbar but still, its stupid). The address bar search thing. I liked the concept, but I
    am so used to the old way, this actually distracts me, I don't want to search my history
    everytime I type a new address. Plus the slide out is huge now making the whole thing feel t....
  16. Is Mozilla The Best Browser?
    (57)
    Hi guys, Can anyone tell me what is the main deference between IE and Mozilla Firefox ? I have been
    using IE (version 6.0) for one year but from now on I have decided to use Firefox. I just want to
    know as to what Mozilla can do which Internet Explorer can not. Thanks! ....
  17. How To Disable "show Hidden Files And Folders" In Folder Option
    (11)
    How to disable "Show hidden files and folders" in Folder Option As you know, you can hide files
    or folders in Microsoft Windows ( to hide a file or folder , right click on file or folder >select
    properties and then select Hide file) But if you open Folder Option and check "Show hidden files
    and folders " you can see hidden files. to disable "Show hidden files and folders" feature follow
    below steps : 1- Click start > Run > type regedit to run Windows Registry Editor. 2- Go to following
    address: QUOTE HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/Current Versio....
  18. Informix To Sql Server (or How To Open .unl Files)
    how to import .unl files into SQL Server 2000 without Informix softwar (2)
    Does anyone know how to import .unl files into SQLServer 2000? My boss gave me this task to migrate
    an old database into SQLServer. I don't have informix installed since the files were sent to me
    via email. All files have .unl extension and I don't have a clue how to view them. I've
    tried opening them using excel but it can't be read. Does anyone know how to do this? Or at
    least know how to open/view the file using excel or any other program that could be easily migrated
    to sqlserver? Please, I need to migrate the files as soon as possible. Thanks....
  19. Internet Browser For Nintendo Ds
    Only for DS Lite :o (38)
    Hey, I want to rant about something - thats why I am here. Today we went to the mall and I went
    past EB Games (they sell games hence the name). I picked up their catalouge and I was looking
    through it while we were walking around the mall. I saw a page on the Nintendo DS. I have a Nintendo
    DS (not a DS lite) and I think it's a really good system. On this page was the DS Internet
    browser, you of course need to have a Wireless Net connection or a Wi-fi USB Adapator for the DS to
    beable to connect to the net. I wanted a USB Connector anyway so that was no trouble. I wa....
  20. Read File (.txt) On Another Website Using Jsp?
    (3)
    in my jsp program,i need to read a file (.txt) on another website,how can i do this? thanks a lot.
    shorten title ....
  21. A Trap17 How-to Guide For Beginners
    Something for those who can't get enough of the Trap17 Readme file (12)
    I am not entirely sure if this the right place to post about this, but here goes anyway... For
    those who find themselves slightly (or considerably more than slightly) clueless about where to get
    started after getting a hosting account, here is an user guide that might potentially help you
    out. I wrote it out of three hours, so forgive me if it's clumsy, but I'm hoping that a few
    people here may find it useful. Feedback is greatly appreciated /smile.gif"
    style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> I'm planning to build on
    a FAQ....
  22. How To Put Music In The Background Of A Powerpoint Presentation
    without having the viewer download the music file (9)
    Well, i made this power poit presentation in memory of my grandfather as many of you kno, passed
    away exactly a week ago....and i am trying to get this song to play as background music..and i did,
    but there is one humongus problem... in order for the people who are viewing it to hear the
    background music they have to download the music file as well ad the powerpoint presentation, which
    on my DSL conntection taked almost 2 minutes, and i could just imagine what it will be for a dial-up
    user (my grandma who wants to see it)... Some people may say, its impossible, but i kn....
  23. Simple C File Handling In Action
    Small code snipet which covers most of basic file handling and navigat (3)
    Yesterday I suddenly got a lot of work. The same work we try to push off, yes you are right all
    formalities to get the code review incorporated and update all source code files with code review
    headers. Imagine if you need to open 300 files one by one and append code review headers at the
    end. Since most files are reviewed in groups of 20 to 30 files. We require one header to be placed
    in say 20 to 30 files. To simplify I went back to my class assignment days and wrote this small c
    utility to open all files passed on command line and open attach code review headers an....
  24. Transfer File Of Any Size Using Winsock Control
    Winsock Help (5)
    This tutorial shows how to transfer file of any size using winsock control. - Open VB; - Select
    standard exe; - Press Ctrl + t to show the add component window; - Select winsock control and
    microsoft common dialog; - Add one winsock control in the project; - Name it winsock1; - If you want
    to add chat then add another winsock and name it winsock2; - Insert another winsock object if you
    want to add chat also; - Add a microsoft common dialog box; - Name it cd; - We will use this
    winsock1 object to transfer the file and winsock2 for chat; ------------- The basic idea : ....
  25. My File Manager Is Working
    (2)
    I tried to change the html for my site in file manager but it just has the default page - the one
    when you activate your site. /sad.gif' border='0' style='vertical-align:middle' alt='sad.gif' />
    How do i change files?....
  26. Does Anyone Know How To Make Exe Files
    (17)
    Does anyone know any software for making exe files, I want to make simple programs not propper
    one's. Thanks.....
  27. Read-only Folders In Xp
    Can't change Read-Only attribute in XP (11)
    Hi, I am working with a firma. We use WinCvs which is a software similar to perforce. I downloaded
    the developement to C: (eg. c:/development) The folder c:/development and the folders under it have
    Read-Only permisions. I need to remove that restriction. I press right-button, i unchecked the
    read-only check-box and i apply to this folder and folders under it. Whe it finisehd i click ok. Whe
    i press the right button again i discovered that the folder has still the read-only attribute. So it
    seems nothing changed. something similar happen to you? How can i uncheck the ....
  28. Mozilla Firefox Poll
    Give your view about the FireFox browser (75)
    Hey guys, Lemme know what you think abou the Mozilla Firefox browser. I personally think it out
    runs Microsoft Internet Explorer mainly cos of the convenience of having all the windows in one main
    window, plus enhanced security features. What do you think? Cheers! Yasir /smile.gif'
    border='0' style='vertical-align:middle' alt='smile.gif' /> ....
  29. Converting Video Files From One Format To Another
    help plz :) (6)
    hey i have learnt this nice way to open mov files in imageready and insert them in sigs,graphics and
    other stuff its really cool,this only works with .mov files and i really need to know if sumone here
    can do that,i need to change a wmv file into a .mov file so i cant add the movie to a sig,i have
    tried many video format conversion programs but they dont accept the mov format,the mov format is a
    quicktime video format,so anyone here know how to change a video file into a quicktime mov video
    format? thnx in advance....
  30. What browser do you use?
    (682)
    I use IE 6, enhanced from Win XP SP2. I want to see what other people use for browsers, and maybe
    start a discussion. This place needs more activity... /wink.gif" style="vertical-align:middle"
    emoid=";)" border="0" alt="wink.gif" />....

    1. Looking for file, browser, listing, folders, files,

Searching Video's for file, browser, listing, folders, files,
Similar
How Can You
Get Audio
Files From
Itunes
Videos?
Japanese
Browser
Called
Sleipnir
Naming Web
Page Files -
Which way
you like-
MyPage.html
or
my-page.html
or
my_page.html
Audio Files?
Jar
Executable
Files
Scroll
Message On
Top Of Your
Browser..
Internal
File
Transfer
Best Browser
To Desighn
Your Site To
- not much
of a
question but
more like a
statement
Making My
Own Browser
- Uhm...need
a name
Best Way To
Transfer
Files - I
just bought
a laptop
1350 Great
Free Logos
(jpg + Psd)
- With both
jpg and
original psd
files to
edit
Free
Software For
File
Recovery -
RECUVA
Where Is The
Bookmarks
File Stored
With Ff2?
Converting
Audio Files
In Vista -
how do you
do it?
Firefox 3
Sucks - Time
For Another
Browser
Is Mozilla
The Best
Browser?
How To
Disable
"show
Hidden Files
And
Folders"
; In Folder
Option
Informix To
Sql Server
(or How To
Open .unl
Files) - how
to import
.unl files
into SQL
Server 2000
without
Informix
softwar
Internet
Browser For
Nintendo Ds
- Only for
DS Lite :o
Read File
(.txt) On
Another
Website
Using Jsp?
A Trap17
How-to Guide
For
Beginners -
Something
for those
who
can't
get enough
of the
Trap17
Readme file
How To Put
Music In The
Background
Of A
Powerpoint
Presentation
- without
having the
viewer
download the
music file
Simple C
File
Handling In
Action -
Small code
snipet which
covers most
of basic
file
handling and
navigat
Transfer
File Of Any
Size Using
Winsock
Control -
Winsock Help
My File
Manager Is
Working
Does Anyone
Know How To
Make Exe
Files
Read-only
Folders In
Xp -
Can't
change
Read-Only
attribute in
XP
Mozilla
Firefox Poll
- Give your
view about
the FireFox
browser
Converting
Video Files
From One
Format To
Another -
help plz :)
What browser
do you use?
advertisement



Need Some Help In File Browser - listing all sub folders and files in them.



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE