Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

List of image in folder

 
Post new topic   Reply to topic    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
navid_gh
Smarty Rookie


Joined: 16 Oct 2008
Posts: 6

PostPosted: Tue Oct 28, 2008 10:33 am    Post subject: List of image in folder Reply with quote

hello
another plugin Laughing
write by me!!!!!! Laughing

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
View user's profile Send private message Send e-mail
prakashl
Smarty n00b


Joined: 31 Oct 2008
Posts: 1

PostPosted: Fri Oct 31, 2008 1:14 am    Post subject: thanks Reply with quote

thanks i'll try
Back to top
View user's profile Send private message
dercyber
Smarty Rookie


Joined: 26 Nov 2008
Posts: 7
Location: Atlanta, GA

PostPosted: Sat Nov 29, 2008 11:45 am    Post subject: Reply with quote

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
View user's profile Send private message
daxx
Smarty Rookie


Joined: 02 Apr 2014
Posts: 14

PostPosted: Tue Apr 15, 2014 12:24 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Plugins All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP