[SOLVED] Output of a Folder?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
th3gh05t
Forum Newbie
Posts: 22
Joined: Tue Apr 20, 2004 11:52 pm

Output of a Folder?

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
th3gh05t
Forum Newbie
Posts: 22
Joined: Tue Apr 20, 2004 11:52 pm

Post by th3gh05t »

Ok.

How do I turn on indexing in .htaccess?

Can you give me some examples of a index script?
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post 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
th3gh05t
Forum Newbie
Posts: 22
Joined: Tue Apr 20, 2004 11:52 pm

Post 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?
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

th3gh05t
Forum Newbie
Posts: 22
Joined: Tue Apr 20, 2004 11:52 pm

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

?>
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

excelente
Post Reply