|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
navid_gh Smarty Rookie
Joined: 16 Oct 2008 Posts: 6
|
Posted: Tue Oct 28, 2008 10:33 am Post subject: List of image in folder |
|
|
hello
another plugin
write by me!!!!!!
input:
folder path
output:
list of images in this folder
use:
{image_export directory=`$ROOT`images/left_images/}
$ROOT:
root website directory in server
parameter:
$image_count:
count of image in this folder
$file_name:
array of images in this folder
example:
$randnum: ' this parameter is for randnum function in randnum plugin that you can find this site '
{randnum floor=0 ceiling=`$image_count`}
{$file_name[$randnum]}
i hope useful for you Code: | <?php
/**
* Smarty {url_check} function plugin
*
* Type: function<br>
* Name: image_export<br>
* Purpose: reading file name and set in array
* @param Smarty
*/
/**
* Name: Navid Ghahramani<br>
* Email: dreamlearn2005@yahoo.com
*/
function smarty_function_image_export($params, &$smarty)
{
$count = -1;
$image_ext = array("jpg","jpeg","JPG","gif","GIF","png","PNG");
$dir = $params[directory];
$dh = opendir($dir);
while (($file = readdir($dh)) !== false) {
$get = explode(".",$file);
$ex = $get[count($get)-1];
if(in_array($ex,$image_ext)){
$file_name_ar[] = $file;
$count++;
}
}
closedir($dh);
$smarty->assign('file_name', $file_name_ar);
$smarty->assign('image_count', $count);
}
?>
|
|
|
Back to top |
|
prakashl Smarty n00b
Joined: 31 Oct 2008 Posts: 1
|
Posted: Fri Oct 31, 2008 1:14 am Post subject: thanks |
|
|
thanks i'll try |
|
Back to top |
|
dercyber Smarty Rookie
Joined: 26 Nov 2008 Posts: 7 Location: Atlanta, GA
|
Posted: Sat Nov 29, 2008 11:45 am Post subject: |
|
|
I think this could be a great plugin for one of the things that I'm trying to do if I could just get it see the directory correctly....
Where are you supposed to declare your $Root variable?
if I leave the function tag for my template just as you have in the example here then I get a blank template returned (well I changed the images sub-dir to \icons since that's in my images folder)
If I try to replace root with the direct path of my localhost webfile then I get an error like:
Code: |
Warning: opendir(.C:\xampp\htdocs\***\images\icons\) [function.opendir]: failed to open dir: No such file or directory in C:\xampp\htdocs\Smarty\Smarty\libs\plugins\function.image_export.php on line 21
|
any help you could give is appreciated _________________ I went into a local computer store and asked a clerk wearing an "I'm a PC" button if they had any books on PEAR and she asked "Do you mean the fruit?" |
|
Back to top |
|
daxx Smarty Rookie
Joined: 02 Apr 2014 Posts: 14
|
Posted: Tue Apr 15, 2014 12:24 pm Post subject: |
|
|
if you want it sorted alphabetically
Code: | <?php
/**
* Smarty {url_check} function plugin
*
* Type: function<br>
* Name: image_export<br>
* Purpose: reading file name and set in array
* @param Smarty
*/
/**
* Name: Navid Ghahramani<br>
* Email: dreamlearn2005@yahoo.com
*/
function smarty_function_image_export($params, &$smarty)
{
$count = -1;
$image_ext = array("jpg","jpeg","JPG","gif","GIF","png","PNG");
$dir = $params[directory];
$dh = opendir($dir);
while (($file = readdir($dh)) !== false) {
$get = explode(".",$file);
$ex = $get[count($get)-1];
if(in_array($ex,$image_ext)){
$file_name_ar[] = $file;
$count++;
}
}
closedir($dh);
sort($file_name_ar);
$smarty->assign('file_name', $file_name_ar);
$smarty->assign('image_count', $count);
}
?> |
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|