I am drawing a canvas and I convert it to dataUrl before I save it into database. The database column for the image is longblob type.
$img = $_POST['picture_dataUrl'];
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$fileData = base64_decode($img);
//saving
$fileName = 'photo5.png';
file_put_contents($fileName, $fileData);
file_put_contents('imgname.txt', $fileData);
//Example of Updating the database
CheckIn::updateAll(['photo1' => $fileData],['id'=>11]);
I have already successfully update / save it into the database. The question is when I wanted to download the image DIRECTLY (click on the image link in database) from database, it works but it being download with the extension .bin, example like photo5.bin
, I need to change it myself to jpg, png etc.
Is there anyway to change the extension of the image when I download directly from database? Thanks