I am working on a legacy system that stores files in the DB as LONGBLOB
What I am trying to achieve is that the user can visit a URL and download a specific file. Now on the part where I try to read the file, I believe I am missing something. PHP is giving me readfile() expects parameter 1 to be a valid path, string given [] []
So I can deduce that I cannot directly feed the LONGBLOB
into the readfile()
method. Is there another way of piping the file out to the user?
Here is the code I am trying to use at the moment:
$stmt = $this->db->prepare('SELECT * FROM DOC_Documents WHERE DOC_ID = ?');
$stmt->execute([$docID]);
$document = $stmt->fetch();
$filename = str_replace(' ', '', $document['DOC_Name']);
$filename .= '.';
$filename .= $document['DOC_Extension'];
header($_SERVER["SERVER_PROTOCOL"] . " 200 OK");
header('Content-Description: File Transfer');
header("Content-Type: " . $document["DOC_Type"]);
header("Content-Disposition: attachment; filename=" . $filename);
readfile(trim($document['DOC_File']));