欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php讀取圖片內(nèi)容并輸出到瀏覽器的實現(xiàn)代碼

 更新時間:2013年08月08日 08:54:43   作者:  
如果php以圖片,zip,exe等文件輸出到瀏覽器,而前面還輸出了其他字符,那就會是你看到的亂碼

代碼很簡單,網(wǎng)上都能找到,但在我機(jī)子上就是顯示不出來,顯示出的一直是這個php文件路徑,

費了點時間才搞定,原來是我的<?php這個標(biāo)簽前面有多的空格,刪掉就ok了,細(xì)節(jié)問題,粗心得很,真的很無語。

網(wǎng)上查了下,有這樣一說:
如果php以圖片,zip,exe等文件輸出到瀏覽器,而前面還輸出了其他字符,那就會是你看到的亂碼。
應(yīng)該是輸出圖片前有輸出空格或其他字符造成的,可以檢查一下輸出圖片前有沒有其他字符,
如果是utf-8編碼記得保存為無BOM的文件。
相關(guān)代碼如下:

復(fù)制代碼 代碼如下:

class imgdata{
        public $imgsrc;
        public $imgdata;
        public $imgform;
        public function getdir($source){
                $this->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();

相關(guān)文章

最新評論