Home > Backend Development > PHP Tutorial > PHP code to extract an image file and display it on the browser

PHP code to extract an image file and display it on the browser

WBOY
Release: 2016-07-25 09:03:24
Original
955 people have browsed it
  1. $size = getimagesize($filename); //Get mime information
  2. $fp=fopen($filename, "rb"); //Open the file in binary mode
  3. if ($size && $fp) {
  4. header("Content-type: {$size['mime']}");
  5. fpassthru($fp); // Output to browser
  6. exit;
  7. } else {
  8. // error
  9. }
  10. ?>
Copy code

The amount of code is less than 1/10 of the original, and the speed is N times faster.



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template