...

View Full Version : File Directory HELP PLEASE!!!!



dagr81
03-06-2007, 10:43 PM
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);

?>

Inigoesdr
03-06-2007, 11:05 PM
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.

$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
Options +Indexes in it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum