Experience Sharing PHP display pictures

Source: Internet
Author: User

First, prepare several title images and name them:

Img_1.jpg, img_2.jpg, img_3.jpg, img_4.jpg, img_5.jpg, img_6.jpg.

Of course, you can also use other types of images, such as gif. Then, upload these images to a folder, for example, "/images/random ".

Next, use the following PHP to display the Image Code:

 
 
  1. <? Php echo rand (1, 6)?>
  2. . Jpg "border =" 0 "/>
  3. <! -- Note: "/images/random"
    Save the folder path of the random image. You should
    Replace with the actual path -->

Is it easy to display pictures in PHP?

This method is a little troublesome because you need to rename the image according to the above rules. If you do not want to rename the image, you can use the following method, but you need to write several more lines of PHP code. :-)

 
 
  1. < ?php  
  2. $dir = $_SERVER['DOCUMENT_ROOT']
     . "images/random";  
  3. chdir ($dir);  
  4. $images = glob("*.{gif,png,jpg}
    ", GLOB_BRACE);  
  5. $file = $images[array_rand($images)];  
  6. ?> 
  7. < img src="< ?php echo ("/
    images/random/$file"); ?>"
     border="0" /> 

Call images from other websites (online album)

 
 
  1. < ?  
  2. $id=rand(1,5);  
  3. $image[1]='http://farm.static.flickr.com/1.png';  
  4. $image[2]='http://farm.static.flickr.com/2.png';  
  5. $image[3]='http://farm.static.flickr.com/3.png';  
  6. $image[4]='http://farm.static.flickr.com/4.png';  
  7. $image[5]='http://farm.static.flickr.com/5.png';  
  8. header("location:$image[$id]");  
  9. ?> 

The above code example is related to the implementation of PHP image display. I hope it will be helpful to you.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.