Showing Directories
Posted: Thu Aug 30, 2007 12:32 pm
Hi
my friend wanted me to make a script that lists files in a directory and has the directories on top. I haven't looked for a script from anyone else to do this, I'd like to start from scratch and get it working on my own. Here is some stuff i made from a script that i found 4 years ago.
The output so far is like this
a httpd/unix-directory
a httpd/unix-directory
z httpd/unix-directory
.. httpd/unix-directory
a httpd/unix-directory
z httpd/unix-directory
.. httpd/unix-directory
a httpd/unix-directory
test httpd/unix-directory
z httpd/unix-directory
I think the repeating has something to do with the while statement? My heads all clouded now so could someone help me a little to get it to just print that very last result? Thanks
my friend wanted me to make a script that lists files in a directory and has the directories on top. I haven't looked for a script from anyone else to do this, I'd like to start from scratch and get it working on my own. Here is some stuff i made from a script that i found 4 years ago.
Code: Select all
<?php
$path = "/home/peacher/public_html/directory/";
// Open the folder
$dir_handle = @opendir($path) or die('Unable to open $path');
// Loop through the files
/////this will list directories
while ($file = readdir($dir_handle))
{
if($file == "." )//what files not to display
continue;
//if the file is a folder
if((mime_content_type($file)) === 'httpd/unix-directory')
{
$files[] = $file;////puts the files into an array and sorts them
sort($files);
foreach ($files as $a) ///prints just the name
{
echo $a;
print(' ' . mime_content_type($a));
print('<br>');
}
print('<br>');
}//endif
}
// Close
closedir($dir_handle);
?>a httpd/unix-directory
a httpd/unix-directory
z httpd/unix-directory
.. httpd/unix-directory
a httpd/unix-directory
z httpd/unix-directory
.. httpd/unix-directory
a httpd/unix-directory
test httpd/unix-directory
z httpd/unix-directory
I think the repeating has something to do with the while statement? My heads all clouded now so could someone help me a little to get it to just print that very last result? Thanks