View Full Version : browse directory from browser..

05-18-2004, 07:15 PM
How can I let the user of my web site browse a specific directory in the server.. he can save files from this directory and open them.. each user will have a username, so each one of them can only view the directory with his user name...
what i want is that whenever the user click in a button called view directory he can see his directory pop-up for him or opened in the browser..How can I do this??????

05-18-2004, 09:13 PM
Hmm.. how do you want them to be able to download and upload files? By dragging and dropping? This is not a PHP issue, and not something that is doable using PHP (I don't think so anyway...).

I would think that this is an FTP issue or something of that like.

If you want a PHP solution, it'll look something like a directory listing with hyperlinks that you can click and save/open, and a file input and a PHP upload file script.

Check out the following links:

If you have further questions, just post back.

Hope that helps,

05-18-2004, 09:51 PM
What I really nead is to let the user to browse the actual directory on the server...

05-18-2004, 10:09 PM
I have a script somewhat similar to what you want, minus the upload features.

What I recommend you do, is create a file named ls.php, and a file named whatever you want, to browse the direcory. I used mine as index.php. DO all the coding for the template/ whatever u call it, then, at the beginning of the page, before the <HTML> tag, insert this php code:

$file="YOURDIRECTORY:" . $_GET['file'];
$dir = $file;
$dir = $file;


Put: include("./ls.php"); wherever you plan on the links being displayed.

Then save that, and open up ls.php

Here is the code I use for mine, minus the content:

if ($directory = opendir("$file")) {
while (false !== ($file = readdir($directory))) {
if ($file != "." && $file != "..") {
$link = $file;
$link = str_replace("'","%27",$link);
$link = str_replace("&","%26",$link);
$dir = str_replace("I:", "", "$dir");
$ext = substr(strrchr($file, '.'), 1);
print("<a href='./index.php?file=$dir" . "/" . "$link' title=''><b>$file</b></a>");
print("<a href='./index.php?file=$dir" . "/" . "$link' title=''><b>$file</b></a>");

This should work, I had to edit it quite a bit to remove a lot of things you would not want (filter out everything but mp3's, etc.)

Whenever you want to open a directory to browse, you would simply go to:


of course, your links would already do that on their own...
hope that helps

05-18-2004, 10:10 PM
if your using IE, access it through FTP (eg: ftp://www.site.com/)

05-18-2004, 10:43 PM
l3vi >>> I think your code will list all the content of the directory as links, right??? if it is........I am sorry but this is not what I want...

missing-score >>> believe it or not.... I don't know any thing about ftp..and I don't how to use it in a web application?????

05-18-2004, 11:30 PM
So are your users going to be using IE (so basically, is it an intranet site where you can control the users somewhat)? Or could they be using different browsers?

If it's IE only, check out these links:

Basically you need to setup an FTP server (on a Windows server, I've had good experiences with GuildFTPd) and you can setup user groups and user accounts and set their restrictions. In this way, you can use PHP to create the link to view their directory that might end up looking something like this:

<a href="ftp://username:password@ftpserver/url-path">View your directory</a>

As you know who the user is, you can use PHP to plugin the username/password, or leave the :password part out and have the user input their password.. (security reasons?)

For each user, you can setup a directory structure, start and root directories, etc.. Taking the FTP route, you open up a lot of options; however, you're somewhat restricted to IE. I'm not sure what would happen in other browsers..


l3vi >>> I think your code will list all the content of the directory as links, right??? if it is........I am sorry but this is not what I want...

Why not? Because how do you plan to save files and open them from this directory?

he can save files from this directory and open them..

Based on that, I'm assuming you want it to look like Windows Explorer. So this makes feel more like you should be taking the FTP route.

But either way, did you check out any links from my first post? You didn't comment on any of them.. we need feedback to see what it is you want, because I'm not sure that I'm clear as to what it is you're looking for.

Let us know your thoughts..

05-19-2004, 12:38 AM
l3vi >>> I think your code will list all the content of the directory as links, right??? if it is........I am sorry but this is not what I want...

Yes, it will list them as links, and if you click on the link, it will open the directory in the same way, until it finds files, similar to browsing something in Windows. You can easily change the apperance of the files to have folder and file icons as they do in Microsoft. When it gets to a file, you could do basically the same thing, but add a piece of code that determines whether or not $_GET[file]; is a file, or a directory (is_file()) and if it is a file, run a command to do whatever you want it to do when they attempt to open a file (i.e. download, edit, remove, etc.)

What I gave you was not an entire script that would allow user functions and all of that. I figured you didnt want to use FTP, because you never replied to any of the posts and said whether or not u would use it. You could code in a user login script, and a user database, that would specify a directory for each user, most likely their usernames, and instead of specifying a specific directory, you would have the ls.php file read from the database, and use what the script got as $file. You could also implement your own uploading,etc. code into this.

Of course, I would also somewhat recommend FTP, if you dont want to spend a lot of time coding a multi-browser code to do what you can do in IE through FTP. I would also recommend GuildFTPd, I use that as well, and it works great. Of course, FTP is mainly only good for IE. It does not let a user upload files, etc. in browsers such as mozilla.