/ Published in: PHP

Outputs an image path from a defined directory.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php $path_to_images = "/images/"; // path to your images $default_img = "image.gif"; // image to display if directory listing fails function getRandomImage($thispath, $img) { if ( $list = getImagesList($thispath) ) { $img = $list[$num]; } return $thispath . $img; } function getImagesList($thispath) { $ctr = 0; // can add checks for other image file types here $images[$ctr] = $img_file; $ctr++; } } return $images; } return false; } ?> <img src="<?php echo getRandomImage($path_to_images, $default_img) ?>;">
Comments
