PHP implementation extracts an image file and displays the code in the browser _php tutorial

Source: Internet
Author: User
Last year did a project, to the user upload image file list, when the user click on a file name, you can display this image.

Because to consider compatible with a variety of image formats, I used the GD library to determine the specific kind of image file (MINE), and then call the corresponding images generated function imagecreatefromxxx (), Generate an IMG, and then output this IMG in JPEG format to the browser, Although made, but always feel dissatisfied.

Today has the opportunity to reconsider this feature, in the PHP manual found a few lines of code, concise and crisp, completely can achieve the function I want, do not need the GD library

Copy CodeThe code is as follows:
$size = getimagesize ($filename); Get MIME Information
$FP =fopen ($filename, "RB"); Binary mode Open File
if ($size && $fp) {
Header ("Content-type: {$size [' MIME ']}");
Fpassthru ($FP); Output to Browser
Exit
} else {
Error
}
?>


The amount of code is my original 1/10 is less than, faster than n times.

http://www.bkjia.com/PHPjc/326070.html www.bkjia.com true http://www.bkjia.com/PHPjc/326070.html techarticle last year did a project, to the user upload the image file list, when the user click on a file name, you can display this image. Because you want to consider compatible with a variety of different image grids ...

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