如何在PHP中添加blob图像FIrebird? [英] How to add blob image FIrebird in php?
本文介绍了如何在PHP中添加blob图像FIrebird?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
无法将照片添加到FIrebird.编写这样的代码
can't add a photo to FIrebird. Writing such a code
$imgSrc='Desert.jpg';
$img_src = $imgSrc;
$imgbinary = fread(fopen($img_src, "r"), filesize($img_src));
$img_str = base64_encode($imgbinary);
$blh = ibase_blob_create($this->db);
ibase_blob_add($blh, $img_str);
$blobid = ibase_blob_close($blh);
$row = false;
/*$fd = fopen('Desert.jpg', 'r');
$blob = ibase_blob_import($fd);
fclose($fd); */
$query = ibase_query($this->db, "INSERT INTO \"ud_ab\" (FILES) VALUES (?)", $img_str ) or die(ibase_errmsg());
if($query) $row = true;
return $row;
尝试将图片转换为base64格式,并写了ibase_blob_add.没有帮助
Tried to translate the picture in base64 format, wrote ibase_blob_add.Nothing helps
推荐答案
这是用于保存图像的示例代码,但在blob字段中
This is sample code for saving images, but in blob field
define('MAX_SEGMENT_SIZE', 65535);
function blob_create($data) {
if (strlen($data) == 0)
return false;
$handle = ibase_blob_create();
$len = strlen($data);
for ($pos = 0; $pos < $len; $pos += MAX_SEGMENT_SIZE) {
$buflen = ($pos + MAX_SEGMENT_SIZE > $len) ? ($len - $pos) : MAX_SEGMENT_SIZE;
$buf = substr($data, $pos, $buflen);
ibase_blob_add($handle, $buf);
}
return ibase_blob_close($handle);
}
$blob = blob_create(file_get_contents('Desert.jpg'));
$query = ibase_query($this->db, "INSERT INTO \"ud_ab\" (FILES) VALUES (?)", $blob) or die(ibase_errmsg());
这篇关于如何在PHP中添加blob图像FIrebird?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文