Let me explain my problem.
I have a list of folders. The top level folder contains subfolders. Each subfolder contains the same structure. Something like this:
Top Level Folder
• Subfolder1
o Project_Contents
Changes
Examples
Requests
Other
• Subfolder2
o Project_Contents
Changes
Examples
Requests
Other
• Subfolder3
o Project_Contents
Changes
Examples
Requests
Other
I hope the list above helps explain the structure. Within each subfolder I also have an index.php and a project.php file.
I have been trying to figure out how to have each project.php page auto index the folders contents. So far I have been working with getting index.php to autoindex the folder contents and then use php include to list the data on the page. I have been toying with Autoindex from sourceforge but it doesn’t allow me to do it the way in need to.
I can index the contents but it only lists the names of the folders. It doesn’t show subfolders or the contents within the subfolders.
<?php
if ($handle = opendir('./project_contents/')) {
echo "Files:\n";
while (false !== ($file = readdir($handle))) {
echo "$file\n";
}
closedir($handle);
}
?>
Any suggestions?
Not the usual PHP folder indexing
Moderator: General Moderators
-
bigfatdummy
- Forum Newbie
- Posts: 2
- Joined: Wed Sep 10, 2008 4:24 pm
-
pawarnilesh4u
- Forum Newbie
- Posts: 6
- Joined: Thu Aug 21, 2008 10:16 am
- Location: Mumbai - India
Re: Not the usual PHP folder indexing
you have to use recurssion here to display the listing as below
function getFiles($filename)
{
if(is_dir ( string $filename ))
{
if ($handle = opendir($filename)) {
echo "Files:\n";
while (false !== ($file = readdir($handle))) {
echo "$file\n";
if(is_dir($file))
getFiles($filename.$file);
}
}
}
else
echo $filename;
}
<?php
if ($handle = opendir('./project_contents/')) {
echo "Files:\n";
while (false !== ($file = readdir($handle))) {
echo "$file\n";
if(is_dir($file))
getFiles('./project_contents/'.$file);
}
closedir($handle);
}
?>
function getFiles($filename)
{
if(is_dir ( string $filename ))
{
if ($handle = opendir($filename)) {
echo "Files:\n";
while (false !== ($file = readdir($handle))) {
echo "$file\n";
if(is_dir($file))
getFiles($filename.$file);
}
}
}
else
echo $filename;
}
<?php
if ($handle = opendir('./project_contents/')) {
echo "Files:\n";
while (false !== ($file = readdir($handle))) {
echo "$file\n";
if(is_dir($file))
getFiles('./project_contents/'.$file);
}
closedir($handle);
}
?>