Support Forum Softcomplex logo
About Us  | Services  | Download  | Order  | Support  | |
| Search | Today's Posts | Stats | Board Rules | Not logged in [ Login | Register ]
go to bottom
Last active: Never

Printable Version | Subscribe | Add to Favourites   Post new thread
Author: Subject: PHP Code - List files of particular types in the directory
tigra
Administrator

Posts: 2049
Registered: 6/17/2002
Location: US, CO
Member Is Offline
posted on 8/1/2007 at 07:14 PM Reply With Quote
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
View User's Profile View All Posts By User U2U Member
Post new thread

Related Links:

Go To Top


Powered by XMB 1.9.1 Nexus
Developed By Aventure Media & The XMB Group © 2002-2004