WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Select random Image from any directory
Categories : PHP, Beginner Guides, Filesystem Click here to Update Your Picture
Dimitris T
Date : Jun 12th 2005
Grade : 3 of 5 (graded 13 times)
Viewed : 21171
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Dimitris T
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

This code can de used to select a random image from any directory. You can use the code for creating a banner selector also.

<?
$dir
=opendir("/path/to/your/images/folder/");

$i=0;
while(
$imgfile=readdir($dir))
{
     if (
$imgfile != "." && $imgfile!="..")
         {
       
$imgarray[$i]=$imgfile;
       
$i++;
        }
}

closedir($dir);

$rand=rand(0,count($imgarray)-1);

    if(
$rand >= 0)
    {
    echo
'<img src="../images/gallery/'.$imgarray[$rand].'" width="170" height="137">';
//replace path, width & height sizes to fit your needs
   
}
?>



Convert a File database into MySQL
Categories : PHP, Filesystem, Databases, MySQL, Beginner Guides
Introduction to Language Files
Categories : PHP, Filesystem, Beginner Guides
A flat file counter
Categories : PHP, Cookies, Filesystem, Beginner Guides
PHP based Contact email form with multiple recipients, text file based, supports departments.
Categories : PHP, Email, Beginner Guides, Filesystem
Link Submition - Allow your visitors to submit links to the site.
Categories : PHP, Arrays, Filesystem, Beginner Guides
Creating a Language File
Categories : PHP, Beginner Guides, Filesystem
Simple image counter
Categories : PHP, Graphics, Filesystem, Beginner Guides
Selecting a random line from a text file
Categories : PHP, Filesystem, Arrays, Beginner Guides
My Box - PHP Class that calculates the volumetric weight of a package.
Categories : PHP, Object Oriented, PHP Classes, Beginner Guides, Payment Gateways
for each record, do this to the first record, and do that to any subsequent record
Categories : PHP, Databases, MySQL, Beginner Guides
Current Page's URL using PHP
Categories : PHP, Beginner Guides, Global Variables
Remote File Size
Categories : PHP, Filesystem, HTTP, Sockets
Fetching product details from the commission junction website using php
Categories : PHP, FTP, Filesystem, Compression
Newbie Notes #5 - To double quote, or single quote, that is the question
Categories : PHP, Beginner Guides, Variables
Quote For the Day
Categories : PHP, Utilities, Filesystem
 Jose Santos wrote :1327
This example is very useful in web interfaces.
Its very good !!