我使用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