Jump to content
UBot Underground

Question: Rotate Images via Image URL


Recommended Posts

Hello.

 

This question is not directly Ubot related. But maybe someone here has an idea how to do that.

 

Challenge:

I would like to use an URL like:

www.mysite.com/picture.gif 

 

But everytime that URL is called, it will show a different picture. So basically a load balancer / rotator for pictures.

 

I have seen a solution with a PHP script, but I can't use that because I can NOT use:

www.mysite.com/picture.php

 

I'm have to use .gif or .jpg in that URL. 

 

Creating a GIF from all the images is also NOT an option. 

 

So the backend server has to rotate the images automatically. Maybe the webserver or some kind of load balancer who does some URL rewriting?

 

Any other ideas how to do this?

 

Thanks in advance for your help

Dan

Link to post
Share on other sites

Could you use ssi or php include?

 

The only must have is that I have to use a URL with .gif or .jpg at the end. 

Everything else is possible.

 

But I can not use a URL like

www.mysite.com/script.php

 

On

www.mysite.com/picture.jpg

www.mysite.com/picture.gif

 

And the rest must be managed on the backend server.

 

 

Dan

 

Link to post
Share on other sites

 This may do it

http://bignosebird.com/recycle2.shtml

 

or you could adapt this

<li><a href="http://">zx</a><br />Some Text</li>
<li><a href="http://">zx</a><br />Some Text</li>
<li><a href="http://">zx</a><br />Some Text</li>
add as many as you want...

and a php file, I call mine ads.php

<?
$delim = "\n";
$cryfile = "random.txt";
$fp = fopen($cryfile, "r");
$contents = fread($fp, filesize($cryfile));
$cry_arr = explode($delim,$contents); fclose($fp); srand((double)microtime()*1000000);
$cry_index = (rand(1, sizeof($cry_arr)) - 1);
$herecry = $cry_arr[$cry_index];

echo $herecry . "\n";

?>
Link to post
Share on other sites

Only .GIF and .JPG are allowed in that URL. 

No 

.html  .php  .cgi

 

A good use case would be posting a picture / banner to a forum.

And I need a solution to show different pictures. And also redirect to different pages depending on which picture is shown when the user clicks that link. 

 

 

 

Dan

Link to post
Share on other sites

I think this is possible via htaccess if I'm not mistaken, here is a Stack thread on it: http://stackoverflow.com/questions/12996453/htaccess-rewrite-serve-php-file-when-gif-is-accessed

 

And this might help: http://www.generateit.net/mod-rewrite/index.php

 

No promises on this but I think it's possible (I'm just not that experienced in htaccess)

Link to post
Share on other sites

assuming every gif isa banner and has the link embedded and all images are ina folder called images.

U ned a php script that rotates them random and a link to open a random gif.

<?php

/////////////////////////////////////////////////////////////////////
// This is the only portion of the code you may need to change.
// Indicate the location of your images 
$root = '';
// use if specifying path from root
//$root = $_SERVER['DOCUMENT_ROOT'];

$path = 'images/';

// End of user modified section 
/////////////////////////////////////////////////////////////////////
 
function getImagesFromDir($path) {
    $images = array();
    if ( $img_dir = @opendir($path) ) {
        while ( false !== ($img_file = readdir($img_dir)) ) {
            // checks for gif, jpg, png
            if ( preg_match("/(\.gif|\.jpg|\.png)$/", $img_file) ) {
                $images[] = $img_file;
            }
        }
        closedir($img_dir);
    }
    return $images;
}

function getRandomFromArray($ar) {
    mt_srand( (double)microtime() * 1000000 ); // php 4.2+ not needed
    $num = array_rand($ar);
    return $ar[$num];
}


// Obtain list of images from directory 
$imgList = getImagesFromDir($root . $path);

$img = getRandomFromArray($imgList);
?> 
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Demo</title>
<style type="text/css">
body { font: 14px/1.3 verdana, arial, helvetica, sans-serif; }
h1 { font-size:1.3em; }
h2 { font-size:1.2em; }
a:link { color:#33c; } 
a:visited { color:#339; }
p { max-width: 60em; }

/* so linked image won't have border */
a img { border:none; }
</style>
</head>
<body>

<h1>Display Random Image Using PHP</h1>

<p><p>Each time the page is loaded an image will be selected at random. When you add more images to select from, you are less likely to get repeats from one page load to the next. </p></p>

<a href="/"><img src="<?php echo $path . $img ?>" alt="" /></a>




</body>
</html>

test this out to see if u get what u need.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...