Home  >  Article  >  Backend Development  >  Implementation code for php to read image content and output it to the browser_PHP tutorial

Implementation code for php to read image content and output it to the browser_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 14:59:31958browse

The code is very simple and can be found online, but it cannot be displayed on my machine. What is displayed is always this php file path,

It took me a while to figure it out. It turned out that there were many spaces in front of my

I checked online and there is this saying:
If php outputs pictures, zip, exe and other files to the browser, and other characters are output in front, then it will be you See the gibberish.
It should be caused by output spaces or other characters before the output image. You can check whether there are other characters before the output image.
If it is UTF-8 encoding, remember to save it as a file without BOM.
The relevant code is as follows:

Copy code The code is as follows:

class imgdata{
public $imgsrc;
public $imgdata;
public function getdir($source){
$this->imgsrc = $source;
}
public function img2data () ,filesize($this->imgsrc));                                                                                                                                                                                                                                                                 echo $this ->imgdata;
//echo $this->imgform;
//imagecreatefromstring($this->imgdata);
}
public function _imgfrom($imgs rc){
$info=getimagesize($imgsrc);
//var_dump($info);
return $this->imgform = $info['mime'];
}
}
$n = new imgdata;
$n -> getdir("1.jpg");
$n -> img2data();
$n -> data2img();







http://www.bkjia.com/PHPjc/328135.html

www.bkjia.comtrue

http: //www.bkjia.com/PHPjc/328135.htmlTechArticleThe code is very simple and can be found online, but it cannot be displayed on my machine. What is displayed is always It took me a while to figure out this php file path. It turned out to be my ?php tag...
Statement:
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