Skip to main content

How to download blob file using php

I'm trying to download this BLOB file from my database.

enter image description here

My php code:

    <?php  
         
$connection =  mysqli_connect("localhost","root","","blog")
               or die('Database Connection Failed');
mysqli_set_charset($connection,'utf-8');

$id = 33;

// Use a prepared statement in production to avoid SQL injection;
// we can get away with this here because we're the only ones who
// are going to use this script.
$query = "SELECT * " ."FROM tblog WHERE id = '$id'";
$result = mysqli_query($connection,$query) 
       or die('Error, query failed');
list($id, $file, $type, $size,$content) = mysqli_fetch_array($result);
header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$file");
ob_clean();
flush();
echo $content;
mysqli_close($connection);
exit;
?>

I used this script to download this BLOB file but it's not downloading any file? anyone help me with this problem? one file from this is pdf others is image.

Thank You



source https://stackoverflow.com/questions/70173601/how-to-download-blob-file-using-php

Comments