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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    File Directory HELP PLEASE!!!!

    I am new at this PHP stuff so please be easy on me. Anyway I'm trying to build a folder so that when I drop a file in that folder, the file automatically becomes a link for someone to download. I know you use a php page but I'm not sure I have it right. I will list my code below and hopefully someone can help me out. I should be able to type in www.website.com/audiovideo and see all files listed in the folder, but it keeps giving me Unable to open /audiovideo. Thanks in advance!!!


    <?
    $path = "/audiovideo";

    $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);

    ?>

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Quote Originally Posted by dagr81 View Post
    I am new at this PHP stuff so please be easy on me. Anyway I'm trying to build a folder so that when I drop a file in that folder, the file automatically becomes a link for someone to download. I know you use a php page but I'm not sure I have it right. I will list my code below and hopefully someone can help me out. I should be able to type in www.website.com/audiovideo and see all files listed in the folder, but it keeps giving me Unable to open /audiovideo. Thanks in advance!!!


    <?
    $path = "/audiovideo";

    $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);

    ?>
    If your path begins with a / it is assumed that you mean to start in the root of the filesystem. So either don't include a / at the beginning or use a ./ to tell the script to start at the current folder.
    PHP Code:
    $path './audiovideo'
    Also, unless you are making this into a regular page you can just have the webserver list the directory contents usually by making a .htaccess file and putting
    Code:
    Options +Indexes
    in it.


  •  

    Posting Permissions

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