I'm trying to write a snippet that list files in a specific directory.
Here's the code:
/*
Snippet name: ListImgInDir
Snippet description: Create a list of images found in directory
Revision: 0.1
Description:
List images created in a directory:
' "<img src='immagini/".$file."'>" '
Snippet Author:
Mao80 & Luca Porru
Snippet Category:
Miscellaneous
Usage:
Insert [[ListImgInDir]] anywhere in the appropriate section of your template.
*/
// *** Script ***
function elencafiles($dirname,$arrayext){
$pre="<li><a href=\"../images/";
$post="\" title=\"Progetto\">Slideshow</a></li>";
$arrayfiles=Array();
if(file_exists($dirname)){
$handle = opendir($dirname);
while (false !== ($file = readdir($handle))) {
if(is_file($dirname.$file)){
$ext = strtolower(substr($file, strrpos($file, "."), strlen($file)-strrpos($file, ".")));
echo $dir . $pre . $file . $post; // echo "<img src='images/".$file."'>";
if(in_array($ext,$arrayext)){
array_push($arrayfiles,$file);
}
}
}
$handle = closedir($handle);
}
sort($arrayfiles);
return $arrayfiles;
}
$array_extimg=array('.jpg','.jpeg','.gif');
$arrayfile=array();
$arrayfile=elencafiles("images/",$array_extimg);
I can't figure what is wrong.
And I would like to call the directory from the snippet as [[ListImgInDir&dir=images]]. If i'm not wrong is easy as call the variable as is automatically added, right?
Thank you,
Rickyx
Edited by Rickyx, 03 May 2011 - 02:50 PM.











