我使用PHP 5.3.5和PostgreSQL。我正在從數據庫中存儲和提取圖像。使用php存儲/從數據庫中提取圖像
爲了存儲我這樣做:
$escaped_data = base64_encode(file_get_contents($_FILES['fileUpload']['tmp_name']));
$fileModel->setBinary_Data($escaped_data);
它的工作,我在我的數據庫(BYTEA場)接收到的圖像。
的問題是提取這一點,我試圖將此代碼提取我的圖片:
$file_info = $fileModel->getBinary_Data($id_file); // This function return the binary_data of the image
header('Content-Type: image/jpeg;base64');
header('Content-Disposition: attachment; filename=' . $file_info['_name']);
base64_decode($file_info['binary_data']));
當我下載的圖片,我無法看到圖像...
回聲在:
echo base64_decode($file_info['binary_data']);
此發生:
http://imageshack.us/f/18/encodez.jpg/
之後,我嘗試使用base64_decode內的函數stream_get_contents,但doens't工作。
有人知道我可以用php下載我的圖片嗎?
感謝反正...
有什麼理由不將文件存儲在文件系統中? – 2012-03-26 22:40:22
是的,我需要在數據庫中存儲圖像,因爲我會實現一個OCR系統。而OCR系統需要讀取數據庫中的圖像。 – KillCloud 2012-03-27 00:28:10
有人有另一種解決方案嗎? – KillCloud 2012-03-27 03:02:35