I've managed to put the code to download a medium blob saved in mysql table. The code works in terms of it retrieves the right file, names it correctly, gives it the correct extension and the browser force downloads it.
The thing is when I try to open file I get an error. That is for example if it is a jpeg file the image won't show. If it is a pdf I do not get the pdf. I checked the file size and it seems to correspond to the stored Blob file size.
I think it is a format issue but do not know how to correct it. Any help appreciated. My code is:
Front End:
<a href="data/docmgmt/get-docmgmt.php?id=<?php=$id;?>">Test</a>
BackEnd:
$doc_id = 24122565639274498;
$conn = new PDO("mysql:host=localhost;dbname=$dbname", $db->id, $db->pass); //connect to db
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //error modes
$stmt = $conn->prepare('SELECT content,type,name,size FROM docmgmt WHERE doc_id=:doc_id');
$stmt->bindParam(':doc_id', $doc_id, PDO::PARAM_INT);
$stmt->execute();
$stmt->bindColumn(1, $lob, PDO::PARAM_LOB);
$stmt->bindColumn(2, $type, PDO::PARAM_STR, 256);
$stmt->bindColumn(3, $name, PDO::PARAM_STR, 256);
$stmt->bindColumn(4, $size, PDO::PARAM_INT);
$stmt->fetch(PDO::FETCH_BOUND);
header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$name");
echo $lob;
Screen Dump of contents of PNG file retrieved