Page 1 of 1
Output of a Folder?
Posted: Mon Jul 19, 2004 4:27 pm
by th3gh05t
Hi,
I have a fodler on my webserver, /www/*foldername*/
How would I make an output so that you can view all the files of that folder?
IE - If I just have the files in a root folder, and go to that folder manually, Apache will list the files with their type, size, etc.
Any help would be greatly appreciated....
Thanks, th3gh05t
Posted: Mon Jul 19, 2004 4:30 pm
by feyd
you can turn indexing on for that directory through .htaccess, I believe.. You could also place an index script that filters out files you wish to hide, or customize the view..
Posted: Mon Jul 19, 2004 4:39 pm
by th3gh05t
Ok.
How do I turn on indexing in .htaccess?
Can you give me some examples of a index script?
Posted: Mon Jul 19, 2004 4:44 pm
by AVATAr
Or do a index.php with:
Code: Select all
<?php
$rep=opendir('.');
while ($file = readdir($rep)){
if($file != '..' && $file !='.' && $file !=''){
if (is_file($file)){
echo $file;
}
}
}
closedir($rep);
?>
i dont test it.
http://www.php.net/manual/en/function.is-file.php
Posted: Mon Jul 19, 2004 4:53 pm
by th3gh05t
Ok. That will output the files in just one line. And no spacing between the files.
I would like for it to be just like Apache does it. Size, Type, Date Modified. And, have the files clickable...
Is this possible?
Posted: Mon Jul 19, 2004 5:00 pm
by AVATAr
yes its posible changing the script y put there...
buy, if you only want it like apache the easy way is using .htaccess (feyd) try google:
http://www.google.com/search?hl=en&lr=& ... tnG=Search
Posted: Mon Jul 19, 2004 5:01 pm
by feyd
Posted: Mon Jul 19, 2004 5:16 pm
by th3gh05t
Thanks for all your help!
This is the final code that works for me..
Code: Select all
<?
//Set Directory
$dirname = "files";
//Open dir into file handle
$dh = opendir($dirname) or die("error opening directory...");
//Loop through each file in the dir
while(!(($file=readdir($dh))===false)) {
if ($file == "." || $file == ".." || $file == "index.php")
{
}
else{
//Create a list with links
echo "<a href='".$file."'>".$file."</a><br>";
}
}
//Close the file handle
closedir($dh);
?>
Posted: Mon Jul 19, 2004 5:29 pm
by AVATAr
excelente