peterallsop
asked on
Listing Files in a Directory
I'm trying to set up part of my website so it's easier to share files. To be frank I have no clue where to search.
There are a few things I would like it to do if any one can help:
- List files in the directory so that I don't need to update the page (auto list )
- Not have the exact location but have them as lets say" file.php?filename=test.rar " (stops leaching)
Formatting would be the easy part (i think) because that could be done in a loop if I'm correct
Please if anyone could give be a shove or a kick in the right direction I would be great full.
There are a few things I would like it to do if any one can help:
- List files in the directory so that I don't need to update the page (auto list )
- Not have the exact location but have them as lets say" file.php?filename=test.rar
Formatting would be the easy part (i think) because that could be done in a loop if I'm correct
Please if anyone could give be a shove or a kick in the right direction I would be great full.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if you don't have access to install the PECL finfo extension, check out the depricated http://www.php.net/manual/en/function.mime-content-type.php
scandir only works with PHP5
Here is a PHP4 alternative
$dir = "/tmp";
$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
sort($files);
print_r($files);
Here is a PHP4 alternative
$dir = "/tmp";
$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
sort($files);
print_r($files);
$dir = "/tmp";
$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
foreach($files as $value) {
echo "file.php?filename=".$valu e."<br />";
}
$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
foreach($files as $value) {
echo "file.php?filename=".$valu
}
ASKER
I'm using PHP 5 just to let you know. Thanks for all the info.
scandir might be a good one http://us.php.net/manual/en/function.scandir.php
Here's a link to all the directory functions http://us.php.net/manual/en/ref.dir.php