PHP擷取緩衝圖片時頁面上顯示亂碼資訊,

來源:互聯網
上載者:User
PHP新手,求助大家,我用開源的PHP QR Code產生二維碼圖片緩衝在本地檔案夾,去讀取時,頁面上報了一堆亂碼的錯誤提示,應該是PHP的提示資訊,不知道怎麼去解決。

讀寫二維碼圖片的代碼
//讀緩衝function read_qrcode_cache($filename){    $result = array();    if (!empty($result[$filename])) {        return $result[$filename];    }    $filepath = PHPMPS_ROOT . 'data/qrcodecache/' . $filename;    if (file_exists($filepath)) {        include_once($filepath);        $result[$filename] = $data;        return $result[$filename];    } else {        return false;    }}//寫入緩衝function write_qrcode_cache($filename, $val){$errorCorrectionLevel = 'L';//容錯層級   $matrixPointSize = 4;//產生圖片大小  $filepath = PHPMPS_ROOT . 'data/qrcodecache/' . $filename;QRcode::png($val, $filepath, $errorCorrectionLevel, $matrixPointSize, 0); }//調用緩衝函數的代碼$value = 'BEGIN:VCARDVERSION:3.0N:' . $info['title'] . 'TEL:0575-87238712TEL;CELL:18969558900ORG:' . $info['title'] . 'END:VCARD';$filename = md5($value).'.png';$data = read_qrcode_cache($filename);if ($data === false) {write_qrcode_cache($filename,$value);}$info['Qrcode'] = $CFG['weburl'] . '/data/qrcodecache/' . $filename;


報的錯誤資訊:

謝謝~~


回複討論(解決方案)

你那不是錯誤資訊,而是 png 圖片資料流
圖片要用 img 標記顯示,直接輸出的瀏覽器自然是亂碼了

你那不是錯誤資訊,而是 png 圖片資料流
圖片要用 img 標記顯示,直接輸出的瀏覽器自然是亂碼了


先謝謝版主的回答,我是通過img標籤輸出的,
圖片也能在頁面正常的顯示

$info['Qrcode'] 是 檔案名稱
顯然你還在哪裡直接輸出了圖片內容

$info['Qrcode'] 是 檔案名稱
顯然你還在哪裡直接輸出了圖片內容


噢,那請問這個要怎麼去處理的

function read_qrcode_cache($filename)
{
$result = array();
if (!empty($result[$filename])) {
return $result[$filename];
}
$filepath = PHPMPS_ROOT . 'data/qrcodecache/' . $filename;
if (file_exists($filepath)) {
include_once($filepath); 去掉這行
$result[$filename] = $data;
return $result[$filename];
} else {
return false;
}
}

function read_qrcode_cache($filename)
{
$result = array();
if (!empty($result[$filename])) {
return $result[$filename];
}
$filepath = PHPMPS_ROOT . 'data/qrcodecache/' . $filename;
if (file_exists($filepath)) {
include_once($filepath); 去掉這行
$result[$filename] = $data;
return $result[$filename];
} else {
return false;
}
}


確實是這個引起的,基礎不紮實,謝謝版主了。
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.