The best way to explain what I need to do is to give an example and here it is:
Say you have a site URL www. website. com/images/banner.gif
and you want the image stored at that URL to be randomly selected from a pool of 6 images:
/banner1.gif
/banner2.gif
/banner3.gif
/banner4.gif
/banner5.gif
/banner6.gif
When a viewer goes to www. website. com/images/banner.gif, one of the 6 banner images would be displayed at random. I know there are scripts out there that allow you to change which image is shown on an html or php page but I need something that will change what image is actually stored at a specific location on my web server.
I'm a beginner in PHP and cannot code this myself -_-;; Wondering if anyone could help me out with this.
Thanks in advance
Change what Image is saved at a certain URL
Moderator: General Moderators
-
goodtimeshaxor
- Forum Newbie
- Posts: 5
- Joined: Wed Jun 06, 2007 11:36 pm
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Examples of this are fairly abundant. 
oraided by an .htaccessyields
or
Code: Select all
<?php
$image = 'example.jpg';
$im = imagecreatefromjpeg( $image );
ob_start();
imagejpeg($im, '', 100);
$len = ob_get_length();
$imagedata = ob_get_clean();
header( 'Content-type: image/jpeg' );
header( 'Content-length: ' . $len );
echo $imagedata;
?>Code: Select all
<?php
$thursday = (date('w') == 4);
if($thursday or isset($_GET['pirate']))
{
$file = 'avatar_sized_pirate.png';
}
else
{
$file = 'avatar_sized.png';
}
header('Content-type: image/png');
header('Content-length: ' . filesize($file) );
readfile($file);
?>Code: Select all
AddType application/x-httpd-php .gif .png .jpg .jpeg
or
-
goodtimeshaxor
- Forum Newbie
- Posts: 5
- Joined: Wed Jun 06, 2007 11:36 pm
feyd | Please use
Some info: The image stored in banner.gif can be random or changed by time (in minutes). Not sure if that will affect the script. Those 4 files are all I have in side directory on the site.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hmm. I can't seem to get it to work and I don't exactly understand how it works either.
I have my images saved to:
http://www.l2luna.com/banner/banner.gif
http://www.l2luna.com/banner/banner1.gif
http://www.l2luna.com/banner/banner2.gif
and I have the first php code you gave to:
http://www.l2luna.com/banner/banner.phpCode: Select all
<?php
$image = 'banner.gif';
$im = imagecreatefromgif( $image );
ob_start();
imagegif($im, '', 2);
$len = ob_get_length();
$imagedata = ob_get_clean();
header( 'Content-type: image/gif' );
header( 'Content-length: ' . $len );
echo $imagedata;
?>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]-
goodtimeshaxor
- Forum Newbie
- Posts: 5
- Joined: Wed Jun 06, 2007 11:36 pm
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
imagegif() only accepts two parameters. Your call has three. What is the third one supposed to be?
Also, if you're not going to manipulate the images, you don't need to use the image functions.. you can simply pull in the file data using file_Get_contents() or one of its equivalents.
Also, if you're not going to manipulate the images, you don't need to use the image functions.. you can simply pull in the file data using file_Get_contents() or one of its equivalents.
-
goodtimeshaxor
- Forum Newbie
- Posts: 5
- Joined: Wed Jun 06, 2007 11:36 pm
Ah. I just copied the PHP code that you showed me and assumed that the 100 meant how many images it ran through. I guess I assumed wrong (I should look at the syntax first before doing that).
Take a look at this directory:
http://www.l2revengeserver.com/banner/
I'm looking to do something like this:
http://www.l2revengeserver.com/banner/banner.gif
It should change every couple minutes.
(Again, thank you for your help. I appreciate it)
Take a look at this directory:
http://www.l2revengeserver.com/banner/
I'm looking to do something like this:
http://www.l2revengeserver.com/banner/banner.gif
It should change every couple minutes.
(Again, thank you for your help. I appreciate it)