"download blob image (stored in the database) to my computer" Code Answer

3

everything you output to the page is considered a file contents. i suppose you don't want "<br>" to be in the contents of your file.

second point - do not do any output before setting headers.

third point - exit('string') outputs 'string', so you output content of your file twice: with echo and with exit.

so, your code should look like:

$id=$_get["id"];
$sql = "select * from table1 where id=$id "; // 1
$res = $con->query($sql);
while($row = $res->fetch_assoc())
{ 
    $name = $row['name'];
    $size =  $row['size'];
    $type = $row['extension'];
    $image = $row['image'];
}

header("content-type: ".$type);
header('content-disposition: attachment; filename="'.$name.'"');
header("content-transfer-encoding: binary"); 
header('expires: 0');
header('pragma: no-cache');
header("content-length: ".$size);

echo $image;
exit();
By Shayan Pourvatan on June 29 2022

Answers related to “download blob image (stored in the database) to my computer”

Only authorized users can answer the Search term. Please sign in first, or register a free account.