Link to home
Start Free TrialLog in
Avatar of peterallsop
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.
Avatar of Zack Soderquist
Zack Soderquist
Flag of United States of America image

You may want to look at some of the built in PHP Directory Functions

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
ASKER CERTIFIED SOLUTION
Avatar of netmunky
netmunky
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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);
$dir = "/tmp";
$dh  = opendir($dir);
while (false !== ($filename = readdir($dh))) {
    $files[] = $filename;
}

foreach($files as $value) {
    echo "file.php?filename=".$value."<br />";
}
Avatar of peterallsop
peterallsop

ASKER

I'm using PHP 5 just to let you know. Thanks for all the info.