View Full Version : Script to show folder contents
dwarfer
05-26-2007, 07:43 PM
My web host doesn't allow you to view the contents of folders it just gives you this page - http://reddwarf.po.gs/misc/
Is there a script or such so I can view the contents of my web folders so it looks something like this - http://www.dwarfer.x10hosting.com/stalker/
Thanks.
djr33
05-26-2007, 07:56 PM
http://www.php.net/manual/en/ref.dir.php
These php functions should be able to help.
Some more specifics here--
From the opendir page -- http://www.php.net/manual/en/function.opendir.php
<?php
$dir = "/etc/php5/";
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
echo "filename: $file : filetype: " . filetype($dir . $file) . "\n";
}
closedir($dh);
}
}
?>
From the readdir page -- http://www.php.net/manual/en/function.readdir.php
<?php
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "$file\n";
}
}
closedir($handle);
}
?>
This should point you toward what you're looking for. Using a mix of those functions should allow you to create a nice directory listing script.
You can even make it layered, so you have the contents of inner folders listed too.
Decide what you want exactly and then look at those pages to see which functions you should use.
Note that all of this requires PHP, so you need it installed on your server and enabled (in many/most cases, it is), and your page must be processed by the PHP parser, so it needs to end with .php, not .htm, etc. All of your html will function the exact same way, but this allows for php as well.
If you enable read and execute permissions for all on that directory, Apache should generate a listing page like that one.
dwarfer
05-28-2007, 06:49 PM
Ah........sorry, I'm not sure how to use the PHP script, could you please help me.
Thanks
djr33
05-28-2007, 07:49 PM
You may just want to try Twey's suggestion.
Otherwise, lok here--
http://www.dynamicdrive.com/forums/showthread.php?p=50943
dwarfer
05-31-2007, 11:11 AM
Thanks it works great!
dplanghi
07-14-2012, 03:55 AM
Sir,
Thanks for your valuable code. I want this code to be used in such way that it will list folder content on conditional basis. For eg.
My files names in folder are as listed
folder name is TEST
/TEST/12400001.DBF
/TEST/12400705.DBF
/TEST/13421201.DBF
I want those files listed on the basis of their file names. i.e.
customize view
1) All files starting with 12 should be listed as for Dated 12 only
2) All files ending with 400001 with a name GPO, 400705 with name TSO etc.
My requirement is not to view actual file names but they should be viewed in customized formats.
Please help and thanks in advance.
djr33
07-14-2012, 04:20 AM
Please post the code you're using. This discussion is also 5 years old, so you should start a new one. The code above is just from the php.net manual.
You should be able to do what you require by using standard "if" statements. But from what you posted, it's unclear where/why you're stuck.
So please post a new discussion with your code, explaining exactly the details of what is the current problem.
For now, I'm closing this discussion (because it's 5 years old).
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.