Jump to content

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
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
[!--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
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.