bellator001
bellator001

Reputation: 1

How to add blob image FIrebird in php?

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;

Tried to translate the picture in base64 format, wrote ibase_blob_add.Nothing helps

Upvotes: 0

Views: 1358

Answers (1)

rstrelba
rstrelba

Reputation: 1954

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());

Upvotes: 1

Related Questions