Display Random Images Script - Image Rotation Code Pictures PHP Rotate HTML
RegisterLogin
Display Random Images Script - Image Rotation Code Pictures PHP Rotate HTML
Post Description: Display Random Images Script - Image Rotation Code Pictures PHP Rotate HTML
Tags: Display, Random, Images, Script, -, Image, Rotation, Code, Pictures, PHP, Rotate, HTML
This Post Was Posted On Feb 29, 2008 By braker #1207
Post Description: Display Random Images Script - Image Rotation Code Pictures PHP Rotate HTML
Tags: Display, Random, Images, Script, -, Image, Rotation, Code, Pictures, PHP, Rotate, HTML
This Post Was Posted On Feb 29, 2008 By braker #1207
Display Random Images Script - Image Rotation Code Pictures PHP Rotate HTML by braker
The only requirement for this to work on your web pages is that you have PHP in your hosting. IF you don't have php, you can signup with www.webune.com for a php plan. if you have php, continue on...
the first thing i tell you to do is to open a text editor like notepad and transfer this code into a blank document:
Code:
<?php
$image_directory = '.';
$image_extension = array();
$image_extension['gif'] = 'image/gif';
$image_extension['jpg'] = 'image/jpeg';
$image_extension['jpeg'] = 'image/jpeg';
$image_extension['png'] = 'image/png';
$image = null;
if (substr($image_directory,-1) != '/') {
$image_directory = $image_directory.'/';
}
if (isset($_GET['image'])) {
$img_info = pathinfo($_GET['image']);
if (
isset( $image_extension[ strtolower( $img_info['extension'] ) ] ) &&
file_exists( $image_directory.$img_info['basename'] )
) {
$image = $image_directory.$img_info['basename'];
}
} else {
$fileList = array();
$handle = opendir($image_directory);
while ( false !== ( $file = readdir($handle) ) ) {
$file_info = pathinfo($file);
if (
isset( $image_extension[ strtolower( $file_info['extension'] ) ] )
) {
$fileList[] = $file;
}
}
closedir($handle);
if (count($fileList) > 0) {
$imageNumber = time() % count($fileList);
$image = $image_directory.$fileList[$imageNumber];
}
}
if ($image!=null) {
$img_info = pathinfo($image);
$contents = 'Content-type: '.$image_extension[ $img_info['extension'] ];
header ($contents);
readfile($image);
} else {
if ( function_exists('imagecreate') ) {
header ("Content-type: image/png");
$picture = @imagecreate (100, 100)
or die ("Cannot initialize new GD image stream");
$bgcolor = imagecolorallocate ($picture, 255, 255, 255);
$font_color = imagecolorallocate ($picture, 0,0,0);
imagestring ($picture, 2, 5, 5, "IMAGE ERROR", $font_color);
imagepng ($picture);
imagedestroy($picture);
}
}
?>
$image_directory = '.';
$image_extension = array();
$image_extension['gif'] = 'image/gif';
$image_extension['jpg'] = 'image/jpeg';
$image_extension['jpeg'] = 'image/jpeg';
$image_extension['png'] = 'image/png';
$image = null;
if (substr($image_directory,-1) != '/') {
$image_directory = $image_directory.'/';
}
if (isset($_GET['image'])) {
$img_info = pathinfo($_GET['image']);
if (
isset( $image_extension[ strtolower( $img_info['extension'] ) ] ) &&
file_exists( $image_directory.$img_info['basename'] )
) {
$image = $image_directory.$img_info['basename'];
}
} else {
$fileList = array();
$handle = opendir($image_directory);
while ( false !== ( $file = readdir($handle) ) ) {
$file_info = pathinfo($file);
if (
isset( $image_extension[ strtolower( $file_info['extension'] ) ] )
) {
$fileList[] = $file;
}
}
closedir($handle);
if (count($fileList) > 0) {
$imageNumber = time() % count($fileList);
$image = $image_directory.$fileList[$imageNumber];
}
}
if ($image!=null) {
$img_info = pathinfo($image);
$contents = 'Content-type: '.$image_extension[ $img_info['extension'] ];
header ($contents);
readfile($image);
} else {
if ( function_exists('imagecreate') ) {
header ("Content-type: image/png");
$picture = @imagecreate (100, 100)
or die ("Cannot initialize new GD image stream");
$bgcolor = imagecolorallocate ($picture, 255, 255, 255);
$font_color = imagecolorallocate ($picture, 0,0,0);
imagestring ($picture, 2, 5, 5, "IMAGE ERROR", $font_color);
imagepng ($picture);
imagedestroy($picture);
}
}
?>
this code will generate a random image for you. this is you can say the engine that makes it all work. now that you have transfered the code into notepad, you can save it as: wallpaperama-generator.php
once you haved samed it in your computer, then upload to your site. Remember, you must have php for this script to work, if you dont' have php yet, get a host who offers PHP. www.webune.com offers PHP Web hosting, check them out.
not all you have to do is to put this tag on whatever page you want to display the random images on a certain directory:
Code:
<img src="http://yourdomain.com/wallpaperama-generator.php">
that's all the time i have right now. hope i helped you
Mike
#1640 1
you have to put the php file in the same directory as your images. had the same error..
Jan 03, 2008 Reply Report abuse
Thomas Cora
#1639 2
do you have a sample site where this runs... for some reason - i can't get it going....
i place the "img src=" yourdomain /wallpaperama-generator.php"
obviously i change my domain name... but no pictures show...
i place the "img src=" yourdomain /wallpaperama-generator.php"
obviously i change my domain name... but no pictures show...
Dec 25, 2007 Reply Report abuse
©2011 Webune Forums - Wed Dec 21, 2011 1:36 pm
Powered by: Webune Forums V3
Powered by: Webune Forums V3