Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Apr 2004
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    browse directory from browser..

    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??????

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:
    http://www.hotscripts.com/Detailed/30239.html
    http://www.hotscripts.com/PHP/Script...pload_Systems/
    http://www.edoceo.com/creo/php-dir-list.php
    http://www.developerfusion.com/show/2892/

    If you have further questions, just post back.

    Hope that helps,
    Sadiq.

  • #3
    New Coder
    Join Date
    Apr 2004
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What I really nead is to let the user to browse the actual directory on the server...

  • #4
    Regular Coder
    Join Date
    Jan 2003
    Posts
    400
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    PHP Code:
    <?php
    if(isset($_GET['file'])){
     
    $file="YOURDIRECTORY:" $_GET['file'];
     
    $dir $file;
    }else{
     
    $file="YOURDIRECTORY:";
     
    $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:

    PHP Code:
    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>");
             }else{
           print(
    "<a href='./index.php?file=$dir" "/" "$link' title=''><b>$file</b></a>");
            }
           }
       }
       
    closedir($directory);

    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:

    index.php?file=YOURDIRECTORY,

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

  • #5
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if your using IE, access it through FTP (eg: ftp://www.site.com/)

  • #6
    New Coder
    Join Date
    Apr 2004
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?????

  • #7
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:
    http://www.intermedia.net/support/ftp/ie5b.asp
    http://www.guildftpd.com/index.php

    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:
    Code:
    <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 assword 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..
    Sadiq.

  • #8
    Regular Coder
    Join Date
    Jan 2003
    Posts
    400
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by romram
    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.
    Last edited by l3vi; 05-18-2004 at 11:43 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •