Random Image Problem

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
dunover
New Member
New Member
Posts: 9
Joined: Thu Dec 11, 2008 4:36 pm

Random Image Problem

Post 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
JeremyBASS

Re: Random Image Problem

Post by JeremyBASS »

Looks like it's working for me.. a new image on every refresh...  ;D
viebig

Re: Random Image Problem

Post by viebig »

i see everything ok too
David_Geoffrey
Forum Members
Forum Members
Posts: 65
Joined: Tue May 22, 2007 10:05 pm

Re: Random Image Problem

Post 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
dunover
New Member
New Member
Posts: 9
Joined: Thu Dec 11, 2008 4:36 pm

Re: Random Image Problem

Post 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!
viebig

Re: Random Image Problem

Post by viebig »

when the image is red, view source code and paste it here, so we can help you
JeremyBASS

Re: Random Image Problem

Post 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
sailor
Forum Members
Forum Members
Posts: 26
Joined: Fri Feb 06, 2009 9:16 pm

Re: Random Image Problem

Post 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.
May the wind allways be on your back, and the sun allways on your face.
dunover
New Member
New Member
Posts: 9
Joined: Thu Dec 11, 2008 4:36 pm

Re: Random Image Problem

Post 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
viebig

Re: Random Image Problem

Post by viebig »

I see... I will send you an UDT, containing a simplified as faster version of random_image tag
dunover
New Member
New Member
Posts: 9
Joined: Thu Dec 11, 2008 4:36 pm

Re: Random Image Problem

Post 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
joecannes
Forum Members
Forum Members
Posts: 93
Joined: Mon Nov 26, 2007 5:00 pm

Re: Random Image Problem

Post 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
viebig

Re: Random Image Problem

Post 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!
Last edited by viebig on Sun Mar 01, 2009 5:17 am, edited 1 time in total.
viebig

Re: Random Image Problem

Post by viebig »

Did anyone test it?
Post Reply

Return to “Modules/Add-Ons”