PHP read the image content output to the browser's code share

Source: Internet
Author: User
This article introduces, using PHP to read pictures, and output to the browser to display a piece of code, there is a need for friends reference.

In PHP, if PHP with pictures, Zip,exe, and other files output to the browser, and the front also output other characters, it will appear garbled. Cause analysis: Output pictures before the output space or other characters caused, at this time, please check the output picture before there are no other characters, if it is utf-8 encoding remember to save as a non-BOM file.

Example:

 
      Imgsrc  = $source;} public Function Img2data () {  $this->_imgfrom ($this->imgsrc);  return $this->imgdata=fread (fopen ($this->imgsrc, ' RB '), FileSize ($this->imgsrc)); } public Function data2img () {  header ("Content-type: $this->imgform");  echo $this->imgdata;  echo $this->imgform;  Imagecreatefromstring ($this->imgdata); Public Function _imgfrom ($imgsrc) {  $info =getimagesize ($IMGSRC);  Var_dump ($info);  return $this->imgform = $info [' MIME ']; }} $n = new Imgdata, $n-Getdir ("1.jpg"), $n, Img2data (), $n-data2img ();? >

Attached, extract an image file and display it on the browser, code:

 
      
  • Related Article

    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.