Our web design and company branding Dream Machine is live!  Click here for the tastiest templates on the net »

Got Weather?
Go here for more [+]

Yahoo Weather  49°F

Bookmark to: Linkarena Bookmark to: Folkd Bookmark to: Digg Bookmark to: Del.icio.us
Bookmark to: Facebook Bookmark to: Reddit Bookmark to: Jumptags Bookmark to: Simpy
Bookmark to: Slashdot Bookmark to: StumbleUpon Bookmark to: Propeller Bookmark to: Furl
Bookmark to: Yahoo Bookmark to: Spurl Bookmark to: Google Bookmark to: Blinklist
Bookmark to: Blogmarks Bookmark to: Newsvine Bookmark to: Blinkbits Bookmark to: Ma.Gnolia

Dream Templates

Revived - Christian T-Shirts, Christian Clothing and Christian Gifts

Music News [+]

Hot PHP Scripts [+]

Scripts - php Random Image Displayer    

Code
<?php


    $folder = '.';


    $extList = array();
    $extList['gif'] = 'image/gif';
    $extList['jpg'] = 'image/jpeg';
    $extList['jpeg'] = 'image/jpeg';
    $extList['png'] = 'image/png';


$img = null;


if (substr($folder,-1) != '/') {
    $folder = $folder.'/';
}


if (isset($_GET['img'])) {
    $imageInfo = pathinfo($_GET['img']);
    if (
        isset( $extList[ strtolower( $imageInfo['extension'] ) ] ) &&
        file_exists( $folder.$imageInfo['basename'] )
) {
    $img = $folder.$imageInfo['basename'];
}
} else {
    $fileList = array();
    $handle = opendir($folder);
    while ( false !== ( $file = readdir($handle) ) ) {
        $file_info = pathinfo($file);
        if (
            isset( $extList[ strtolower( $file_info['extension'] ) ] )
) {
            $fileList[] = $file;
        }
    }
    closedir($handle);


    if (count($fileList) > 0) {
        $imageNumber = time() % count($fileList);
        $img = $folder.$fileList[$imageNumber];
    }
}
if ($img!=null) {
    $imageInfo = pathinfo($img);
    $contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ];
    header ($contentType);
    readfile($img);
} else {
    if ( function_exists('imagecreate') ) {
        header ("Content-type: image/png");
        $im = @imagecreate (100, 100)
            or die ("Cannot initialize new GD image stream");
        $background_color = imagecolorallocate ($im, 255, 255, 255);
        $text_color = imagecolorallocate ($im, 0,0,0);
        imagestring ($im, 2, 5, 5, "IMAGE ERROR", $text_color);
        imagepng ($im);
        imagedestroy($im);
    }
}
?>

Installation
  1. Copy/paste the code above
  2. Name the file random.php
  3. Place in the same directory in which your images reside
  4. Reference random.php in your src. For instance:
    <img src="image_path/random.php"    ...>

Hotscripts.com

Scripts.com

ScriptSearch.com

This is a simple random image displayer. Simply copy/paste/save the code, upload and place into the same directory in which your images reside and reference random.php in your src like so: < img src="image_path/random.php" ...> Works with gif, jpg and png!
back to top back to top
1079