How can I get all folder names from a specific directory and list them using PHP?
Get folder name
Collapse
X
-
scandir is PHP5, so to do the same in PHP4 you would need a different approach, which means a couple more lines of code.
I've done this some time ago, but I couldn't find my own code at the moment, so I found a similar code here :
[PHP]
<?php
// declare the folder
$ourDir = "/home/public_html/folderName";
// prepare to read directory contents
$ourDirList = @opendir($ourDi r);
// loop through the items
while ($ourItem = readdir($ourDir List))
{
// check if it is a directory
if (is_dir($ourIte m))
{
echo "directory: $ourItem <br />";
}
// check to see if it is a file
if (is_file($ourIt em))
{
echo "file: $ourItem <br />";
}
}
closedir($ourDi rList);
?>
[/PHP]
This should work in PHP4 as well as PHP5.Comment
-
That is exactly what I'm trying to get. thanks guys! By the way do you any ways of searching a file from a specific directory? including its subdirectories? and display a list of search results. As of now I'm thinking of using a database for that but I'm still hoping for a better alternativeComment
-
Originally posted by memermoreThat is exactly what I'm trying to get. thanks guys! By the way do you any ways of searching a file from a specific directory? including its subdirectories? and display a list of search results. As of now I'm thinking of using a database for that but I'm still hoping for a better alternative
Anyways, good luck!Comment
-
I could use some help with almost something similar:
I am trying to get php to read the folder name that php is in and write it to a text file.
i.e. www.mydomain.com/john
I need the script to write john to a text file
although this will not work; something close:
<?php
$_SERVER["REQUEST_UR I"]
$your_data =($_SERVER);
// Open the file and erase the contents if any
$fp = fopen("textfile _name.txt", "w");
// Write the data to the file
fwrite($fp, $your_data);
// Close the file
fclose($fp);
?>
The overall all goal is to also perform the following if possible using php.
when it write the folder name:
the folder named one of the two ways:
/bob
/mary-jane
can it upppercase to Bob
can it upper case to Mary Jane and drop the -
anyone have any ideas?
The end result is flash to read the txt file and so it can write it into the flash sction script.
The part I am not sure is after php writes it to the text file, will it happen before flash reads the txt file?
Thanks for any assistance
LLComment
Comment