Random Image

Syalalala~
Hmm… PHP again^^ today i tried to make random image with PHP. I used it on my sidebar to show my photos but in this tutorial I use localhost with apache server (XAMPP). First go to directory c:\xampp\htdocs and create new folder ‘random’. Then open ‘random’ and create new folder again to save your image. For example I create images folder (c:\xampp\htdocs\random\images). Put your images on it, don’t forget to rename your image to numerical number. For example: I have 9 image then I rename it to ‘1.jpg,2.jpg,3.jpg,4.jpg,…,9.jpg’. Finish?

Image name!

Create new blank PHP file on random directory and copy this script:

1
2
3
4
5
6
7
8
9
10
<?
$total='9'; //total images
$type='.jpg'; //file type
$directory='images'; //directory to save images
$n='1'; 
$random=mt_rand($n, $total); //make it random 1 to 9
$name=$random . $type;
echo "<center> 
<img src='$directory/$name' border='0' title='Me' height='180' widht='200'></center>";
?>

Save it to random.php.
Random
Open your browser and try to running random.php with url:
http://localhost/random/random.php. Refresh it to change image^^

Preview on browser...

Now, you can put it on your web page.. Like my blog.. See my picture on side bar :) Give me comment please^^



Related Post:

Post a Comment

Your email is never published nor shared. You're allow to say what you want...

Blogroll Link Update