尝试将此Blob保存到文件并将其加载为图像时遇到很大麻烦。如何将BLOB保存为可读文件,如.txt或.jpg?
使用SQLite管理器(Firefox插件)我能够“另存为”一个文件与我的图像BLOB的内容。结果是一个奇怪的(对我来说)代码。
因为我不能发布“文件的来源”,所以我附上了一个png的例子。
在我的Mac,保存的文件没有extention,但我可以看到它产生的缩略图图像。
所以我想达到同样的结果保存一个文件,但我得到的是一个16个字节的文件,我不能读...
$pic = fopen('pics/thumbnails/pic_'.$id.'', 'w');
fwrite($pic, base64_encode($theFile));
fclose($pic);
*编辑*
$theFile = shell_exec("sqlite3 AddressBookImages.sqlitedb 'select data from ABThumbnailImage where record_id = ".$id."'");
if($theFile != '') {
file_put_contents('pics/thumbnails/pic_'.$id.'.jpg', $theFile);
}
'base64_encode'在这里是一个确定的错误。但是'$ theFile'是什么? – Jon
哦,$ theFile是sqlite查询的结果$ theFile = $ row ['data']; – Pluda
你应该试试'file_put_contents('pics/thumbnails/pic _'。$ id,$ theFile)'。如果这不起作用,那么涉及数据库的问题就会出错。 – Jon