Thursday, August 28, 2008

Code for collect all image files from a folder dynamically using PHP


/* Your file path to getting all the image */
$path_file = "/www/htdocs/evergreenphp/shuffleimages";
$image_array = Collect_images($path_file);

if (is_array($image_array)){
/* Proceed your image related work.. */
} else {
echo "No image on the Path";
}


/* Collect all the images dynamically from a Folder */
function Collect_images($path){
$image_list = "";
$image_array = array();
$path_dir = opendir($path);
while (($files = readdir($path_dir)) !== false) {

$check_file = explode(".", $files);
if (strlen($check_file[1]) > 2)
$image_array[] = $files;
}

if (count($image_array) > 0) {
return $image_array;
} else {
return 0;
}
}
?>

No comments:

Popular Posts