You are here: Re: readdir question « All PHP « IT news, forums, messages
Re: readdir question

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация