Re: custom functions
| From: | chiefmonkey | Date: | Wed, 20 Feb 2002 21:41:16 +0000 |
| Subject: | Re: custom functions | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-2792@lists.php.net to get a copy of this message | ||
Here's the function
function smarty_func_getimage($path) {
$imagelist=array();
$handle=opendir($path);
while(false !==($file = readdir($handle))) {
if ($file !="." && $file !="..") {
$ext=substr($file, -4);
// if you wish to add .png to the list of files
// uncomment the line below and delete the original line
//if ($ext == ".jpg" || $ext==".gif" || $ext==".png") {
if ($ext == ".jpg" || $ext==".gif") {
array_push($imagelist, "$file");
}
}
}
srand((double) microtime()* 1000000);
$names=$imagelist;
$rand_keys = array_rand($names,2);
$adimage=$names[$rand_keys[0]];
$alt=substr($adimage,0,-4);
$adimage="$path/".$adimage;
$size=GetimageSize($adimage);
$display="<img src=\"$adimage\" $size[3] alt=\"$alt\" />";
echo"$display";
closedir($handle);
}
Thanks for the help so far
George
At 15:31 20/02/2002 -0600, Monte Ohrt wrote:
OK, and then what does it do? It shouldn't try to send the image binary to the template, if that is what it's doing. It should return a path to the image, so the browser will go back after the template loads to get the image. so something like this in your template: <img src="{getimagepath}"> where getimagepath would display the path to the image relative to the document root. chiefmonkey wrote:It grabs an image at random from a specified directoryGeorgeAt 15:23 20/02/2002 -0600, Monte Ohrt wrote:What does getimage do exactly? dump image data to the browser? chiefmonkey wrote:crashing now.I now have it working, in as much as it doesn't display an error message, however the browser window won't load and it keepshttp://www.phpinsider.com/php/code/Smarty/George At 15:11 20/02/2002 -0600, Monte Ohrt wrote:$subst('Email.Unsub')wrong syntax for one: {getimage name="val" name2="val2"} chiefmonkey wrote:I am trying to create a custom function so I added it to Smarty.addons and named it smarty_func_getimage I then added it to the custom functions array in Smarty.class'getimage' => 'smarty_func_getimage'and I am trying to call it from my template {getimage:"path/to/images"} but I keep getting this error syntax error: unknown tag - 'getimage TIA George --- You are currently subscribed to smarty as: monte@ispi.net To unsubscribe send a blank email toVisit Smarty's homepage at$subst('Email.Unsub')-- Monte Ohrt <monte@ispi.net> http://www.ispi.net/--- You are currently subscribed to smarty as: monte@ispi.net To unsubscribe send a blank email tochiefmonkey@wisemonkeydesign.co.ukVisit Smarty's homepage at http://www.phpinsider.com/php/code/Smarty/-- Monte Ohrt <monte@ispi.net> http://www.ispi.net/ --- You are currently subscribed to smarty as:To unsubscribe send a blank email to $subst('Email.Unsub') Visit Smarty's homepage at http://www.phpinsider.com/php/code/Smarty/-- Monte Ohrt <monte@ispi.net> http://www.ispi.net/ --- You are currently subscribed to smarty as: chiefmonkey@wisemonkeydesign.co.uk To unsubscribe send a blank email to $subst('Email.Unsub') Visit Smarty's homepage at http://www.phpinsider.com/php/code/Smarty/