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;
}
}
確實是這個引起的,基礎不紮實,謝謝版主了。