/    Sign up×
Community /Pin to ProfileBookmark

Display files in Directory

hello

I have this code to display all of the files in a directory.

But if there is a folder in the directory it will not display, is there a way to make the folder display?

Thanks

[code=php]
<?php
$files = glob(“{$_SERVER[‘DOCUMENT_ROOT’]}/websites/MY 2006/*.*”);
if(count($files) > 0)
{
echo “<h3>Backup Files for my.com 2006:</h3>n<ul>n”;
foreach($files as $path)
{
$file = basename($path);
echo “<li><a href=’http://my.com/websites/my 2006/$file’>$file</a></li>n”;
}
echo “</ul>n”;
}
?>
[/code]

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@bokehJul 07.2006 — Like this:[code=php]function ListChildDirectories($dir)
{
if ($handle = opendir($dir))
{
$output = array();
while (false !== ($item = readdir($handle)))
{
if (is_dir($dir.'/'.$item) and ($item != '.') and ($item != '..'))
{
$output[] = $item;
}
}
closedir($handle);
return $output;
}
else
{
return false;
}
}[/code]
Or like this:[code=php]function ListDescendantDirectories($dir)
{
if ($handle = opendir($dir))
{
$output = array();
while (false !== ($item = readdir($handle)))
{
if (is_dir($dir.'/'.$item) and $item != "." and $item != "..")
{
$output[] = $dir.'/'.$item;
$output = array_merge($output, ListDescendantDirectories($dir.'/'.$item));
}
}
closedir($handle);
return $output;
}
else
{
return false;
}
}[/code]
Copy linkTweet thisAlerts:
@NogDogJul 07.2006 — Just change the "*.*" to "*" and you'll get all file/directory names, not just those with a "." somewhere in them:

[code=php]
$files = glob("{$_SERVER['DOCUMENT_ROOT']}/websites/MY 2006/*");
[/code]
Copy linkTweet thisAlerts:
@comptech520authorJul 10.2006 — When I do it this way with the * instead of *.* it pull the directories up but the other problem is when I click on the link for the directory, I get a forbidden error. Is there a way for when I click on the directory for it to open on the same page?

Thanks
Copy linkTweet thisAlerts:
@NogDogJul 11.2006 — Is there a default file in that directory (index.html, default.htm, etc.)? If not, depending on your webserver set-up, you won't be allowed to just link to and view the directory via the browser (done by FTP-ing that directory). You would have to instead link to a script with a URL query specifying what directory to view, and then have that script read the directory and display the results as in your script, above.
×

Success!

Help @comptech520 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...