Jump to content

Archived

This topic is now archived and is closed to further replies.

php_joe

Removing extensions from directory listings

Recommended Posts

I modified the code provided by [b]shocker-z[/b] in [a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=89695&st=0&p=375454&#entry375454\" target=\"_blank\"]directory listing problem[/a] for listing the contents of a directory so that it wouldn't show the file extensions.

[code]$path = "./";
$dir = opendir($path);
echo "<ul>\n";

while($file = readdir($dir))
{
if ($file != "." && $file != ".." && $file != ".php")
{
list ($name, $ext) = explode (".", $file);
echo "<li><a href = \"" .$path.$file. "\" target = \" _blank\"> ".$name." </a></li> \n";
}
}
echo "</ul>\n";
closedir($dir);[/code]

Anyone know how to make it show only folders, or to specific file types?

Joe

Share this post


Link to post
Share on other sites
You could use the [a href=\"http://pt.php.net/manual/en/function.pathinfo.php\" target=\"_blank\"]pathinfo [/a]function.

From the manual:
[code]
<?php
$path_parts = pathinfo('/www/htdocs/index.html');

echo $path_parts['dirname'], "\n";
echo $path_parts['basename'], "\n";
echo $path_parts['extension'], "\n";
?>
[/code]
Would produce:

/www/htdocs
index.html
html

Share this post


Link to post
Share on other sites
[!--quoteo(post=375531:date=May 21 2006, 12:37 AM:name=yonta)--][div class=\'quotetop\']QUOTE(yonta @ May 21 2006, 12:37 AM) [snapback]375531[/snapback][/div][div class=\'quotemain\'][!--quotec--]
You could use the [a href=\"http://pt.php.net/manual/en/function.pathinfo.php\" target=\"_blank\"]pathinfo [/a]function.[/quote]

Thanks!

Now for what is probably a stupid question...

The opendir() function will only open a folder on my website, right? If I have two websites (hosted on different servers) can I list the contents in a folder located on one website on a page located on the other?

Joe

Share this post


Link to post
Share on other sites
I modified the supplied code, and I could not get it to list the contents in a directory of one of my websites. So, my guess would be that it's not possible. However, I may be wrong.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.