I have a script that creates an image and calls imagepng to output it to the browser. Instead, I would like to store it in a MySQL database (like blob). I know how to read a file in a prepared statement
while ($data = fread($fp, 1024)) { $size += strlen($data); $stmt->send_long_data(0, $data); }
The problem is that I do not want imagepng write to the file so that I can read it back to the database.
Is there an easy way to do this?
UPDATE: This is how I tried to use output buffering:
ob_start(); imagepng($dst_r,null); $img = ob_get_clean(); $db = Database::getInstance(); // Singleton on MySQLi $s = $db->prepare("UPDATE " . $db->getTableName("Users") . " SET `Picture` = ? WHERE `UserID` = ?" ); $s->bind_param('bi', $img, $_POST['UserID']); $s->send_long_data(0, $img); $s->execute();
The database is not updated and there are no errors.
source share