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