| |
 |
June 19th, 09:00 am |
 |
Warning: fopen(userdata.php): failed to open stream: Permission denied in C:\Inetpub\vhosts\mikemania.kawanda.net\httpdocs\users.php on line 19
Warning: fwrite(): supplied argument is not a valid stream resource in C:\Inetpub\vhosts\mikemania.kawanda.net\httpdocs\users.php on line 20
Warning: fwrite(): supplied argument is not a valid stream resource in C:\Inetpub\vhosts\mikemania.kawanda.net\httpdocs\users.php on line 25
Warning: fwrite(): supplied argument is not a valid stream resource in C:\Inetpub\vhosts\mikemania.kawanda.net\httpdocs\users.php on line 32
Warning: fclose(): supplied argument is not a valid stream resource in C:\Inetpub\vhosts\mikemania.kawanda.net\httpdocs\users.php on line 33
Total users online : 1 |
 |
 |
|
|
| Random Image Script |
For this tutorial, you will need to know basic php knowledge and how it works.
This tutorial consists of a code that you can copy and paste so its only a matter
of understanding variables that you will need to change in order for this script
to work.
Basically what this code does is go into a folder (that you specify) and finds
all the images and displays then randomly.
First, lets open your pefered php editor, but due to the simplicity of the code,
we can simply use notepad. Start off my copying the following code into the new
notepad document and save the document as "random.php" Do not close
the document just yet.
| Code
\\ |
<?php
//directory here (relative to script)
$path = 'LOCATION OF THE IMAGES';
$i = 0;
$imgDir = opendir ($path);
while ( $file = readdir( $imgDir ) )
{
//checks that file is an image
$file_type = strrchr( $file, "." );
$is_image = eregi( "jpg|gif",$file_type );
if ( $file != '.' && $file != '..' && $is_image )
{ $images[$i++] = $file; }
}
closedir ($imgDir);
srand( (double) microtime()*1000000 );
$image_name = $path . '/' . $images[rand( 0,sizeof( $images ) -1 )];
$imgSize = GetImageSize( $image_name );
//ends script if no images found
if ( $i == 0 )
die();
//Display the image
readfile("$image_name");
?> |
The $path variable is the script path to which folder on your server you want
the script to look into. Replace LOCATION OF THE IMAGES with
the script path to your desired folder. If you are unsure of how to find the
script path, go here.
Once the correct script path is pasted in, you are essentialy ready to upload.
Make sure this php file, random.php, is uploaded in the same folder as the images
you wanted to randomize. Once you have done this, we are ready to use this aren't
we? To display the images, you would normally put in http://www.site.com/images/myimage.jpg,
but this time, we need to insert http://www.site.com/randomimagesfolder/random.php.
So whereever you want to display this random banner, but in this HTML code in
that place:
| Code
\\ |
| <img src="http://www.site.com/randomimagesfolder/random.php">
|
Extra- To make some images appear more often than others, simply copy them
and make duplicates in the folder. Pretty cheap, but effective.
If you have further qestions, do not hesitate to post your query on the development
boards. Thanks!
|
Written
by MikeMania on October 28 2005 |
|
 |
|
|
|