|
Posted by Janwillem Borleffs on 10/10/21 11:26
Brian wrote:
> Hi all
>
> Below is a bit of code that puts the file list of a dir
> into an array which I use later.
>
> 2 questions.......
>
> 1) how do I get the loop to only show files and not other directories?
>
$thefiles = array();
$reg = '/\.(zip|csv|txt|doc|jpg|bmp|ext|php|htm|html)$/i';
if ($handle = opendir($path)) {
while ($file = readdir($handle)) {
if ($file !== 'fileviewer.php' &&
preg_match($reg, $file) &&
is_file("$path/$file")) {
$thefiles[] = $file;
}
}
closedir($handle);
rsort($thefiles);
reset($thefiles);
}
When $path ends with a trailing slash, do:
is_file("$path$file")
> 2) Quite sure this can't be done other wise hacking would be so easy,
> but is it possible to read the dir on a different server, and get the
> file list
> in date order of creation?
>
Not without directory browsing enabled afterwhich you would to be able to
parse the index file created by the webserver only.
JW
Navigation:
[Reply to this message]
|