Page 1 of 1

Random Image Problem

Posted: Tue Feb 10, 2009 3:27 am
by dunover
I have the latest download of CMS

and am using the random_image tag   The problem am having is I randomly get a red X image. When clicking properties is shows

/images

This is the code I have in the template is



With 8 images...
Site can be seen here
http://64.128.95.108/~custerco/index.php
The big image

The images are in a folder like this  images/front

For the life of my I cannot troubleshoot this issue, can anyone help??

Thanks!
Cori

Re: Random Image Problem

Posted: Tue Feb 10, 2009 4:12 am
by JeremyBASS
Looks like it's working for me.. a new image on every refresh...  ;D

Re: Random Image Problem

Posted: Tue Feb 10, 2009 4:35 am
by viebig
i see everything ok too

Re: Random Image Problem

Posted: Tue Feb 10, 2009 4:00 pm
by David_Geoffrey
Just so you don't think you are going mad, I am getting the red X randomly as well! Maybe it is a browser based problem. I am using IE7 on XP

Re: Random Image Problem

Posted: Tue Feb 10, 2009 6:01 pm
by dunover
I get the red X on IE and Firefox....  I hoping that having alot of photo will minimize the occurrence... but it still comes up!

Re: Random Image Problem

Posted: Tue Feb 10, 2009 6:43 pm
by viebig
when the image is red, view source code and paste it here, so we can help you

Re: Random Image Problem

Posted: Tue Feb 10, 2009 7:27 pm
by JeremyBASS
I just tested on 3 pc across 6 browses and all came out fine... did 10 refreshes each... never one red x... for what it's worth.

viebig is right we need some code from when it's in error... sorry I can't be more helpful.


Jeremy

Re: Random Image Problem

Posted: Tue Feb 10, 2009 7:36 pm
by sailor
It looks like the random image generator is including the "parent directory" in the file list of the images/front directory, on a broken page I see:

Code: Select all

<img src="images/front/..">
where on all the good pages I get something like:

Code: Select all

<img src="images/front/picture_one_foot.jpg">
You need to exclude the folder ".." (parent directory) somehow...

Great looking site BTW.

Re: Random Image Problem

Posted: Fri Feb 13, 2009 11:39 pm
by dunover
Thanks! How would I edit that to excluded?  Copy of plugin code attached

read() ) {
  ++$count;
        }
        $myDir->close();

        $myDir = dir($dirn);
        rewinddir();
        srand(time());
        $randnum = rand(3,($count-2)+1);

        for($i=0;$iread();
                $myimage = $entryName;
        }

return $dirn . "/" . $myimage;
}

function smarty_cms_help_function_random_image() {
?>
What does this do?
Grabs a random image from the image directory specified
How do I use it?
Just insert the tag into your template/page like: {random_image dir="images/albums"}
What parameters does it take?

(optional)dir - directory containing the images.



Author: Robert Campbell<rob@techcom.dyndns.org>
Version: 1.0

Change History:
None

Re: Random Image Problem

Posted: Mon Feb 16, 2009 5:15 pm
by viebig
I see... I will send you an UDT, containing a simplified as faster version of random_image tag

Re: Random Image Problem

Posted: Thu Feb 19, 2009 3:16 am
by dunover
I see... I will send you an UDT, containing a simplified as faster version of random_image tag

ok sounds wonderful, I am new here, how will  that be sent?  thanks for all your help!!!
Corisa

Re: Random Image Problem

Posted: Sun Mar 01, 2009 2:23 am
by joecannes
viebig, can you send me the UDT as well? I am having the same problems with that extension with CMSMS 1.5.2

Re: Random Image Problem

Posted: Sun Mar 01, 2009 5:16 am
by viebig
Hello people!

name it rnd_image

Code: Select all

$dir = (empty($params['dir'])) ? "uploads/images" : $params['dir'];
$myDir = dir($dir);
if(!$myDir) return "<!-- Directory '".$params['dir']."' not exist, aborting -->";
$images = Array();
while($file = $myDir->read()) {
if($file != '.' && $file != '..' && !is_dir($params['dir'].$file)) {	
$ext = strtolower(substr(strrchr($file, "."), 1));	
if(($ext == "jpg" || $ext == "jpeg" || $ext == "gif" || $ext == "png") && strstr($file, $params['exclude']) == "") {
$images[] = $file;
}}}
$myDir->close();
if (sizeof($images) == 0) return "<!-- No images found matching image extensions and excluded pattern -->";
return $dir.'/'.$images[rand(0,sizeof($images)-1)];
we have two optional params:

dir - directory where the files are
exclude - a simple exclude string

the usage is

Code: Select all

{rnd_image dir="uploads/images/random" exclude="thumb"}
This will get a random image from 'uploads/images/random' folder, excluding all images that have 'thumb' on the file name

Also only .jpeg, .jpg, .gif and .png are indexed, so the dir can contain another files too. Directories, '.' and '..' will not get indexed.

So, try it, let me know if it works for you and if it has bugs(I didnt test it)

Cheers, and applaud me!

Re: Random Image Problem

Posted: Tue Mar 03, 2009 3:39 pm
by viebig
Did anyone test it?