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