tigra
Administrator
Posts: 1976
Registered: 6/17/2002
Location: US, CO
Member Is Offline
|
| posted on 8/1/2007 at 07:14 PM |
|
|
PHP Code - List files of particular types in the directory
We use this code in one of the Tigra Fader demonstrations but it can be useful in other situations. This sample lists all image files in the specified
directory in the comma separated list of JavaScript strings. The output format can be easily changed.
| Code: |
$s_path = 'img/';
$a_types = array ('jpg', 'gif', 'jpeg', 'png');
$a_images = array ();
$h_dir = opendir($s_path);
while ($s_file = readdir($h_dir)) {
$s_type = strtolower(substr(strrchr($s_file, '.'), 1));
if (in_array($s_type, $a_types))
array_push($a_images, "ntt'$s_path$s_file'");
}
closedir($h_dir);
sort($a_images);
echo join(',', $a_images);
|
You can find this code in working sample inside the download package available at:
http://www.softcomplex.com/products/tigra_fader/download.html
|
|
|
|