Experience sharing PHP Display Picture _php tutorial

Source: Internet
Author: User

First prepare a few title pictures, 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. < img src= "/images/random/img_
    PHP echo rand (1,6) ?>
  2. Border = "0" />

Is it easy to display images in PHP?

A little bit of a hassle with this approach is to rename the picture according to the rules above. If you don't want to rename the picture, you can also use the following method, but write a few 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 a picture on another website (Web 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 the PHP display image of the relevant implementation method, I hope to help you some.


http://www.bkjia.com/PHPjc/446078.html www.bkjia.com true http://www.bkjia.com/PHPjc/446078.html techarticle first prepare several title pictures, 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 ...

  • 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.