july morse
july morse

Reputation: 1

How To Make Zip Blob Files Ready for Download From MySQL Database

I have created a database with a table that contains blob wherein I saved ZIP and PDF files. The problem is, how can I make these files ready for download through PHP scripts?

Upvotes: 0

Views: 3408

Answers (1)

tttony
tttony

Reputation: 5082

Like this:

$name = "file.zip"; // or file.pdf
$file_content = $blob_row['file_content'];

header('Content-Description: File Transfer');

header('Content-Type: archive/zip'); // or archive/pdf

header('Content-Disposition: attachment; filename=' . $name);

header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . strlen($file_content));
ob_clean();
flush();

echo $file_content;
exit;

Upvotes: 2

Related Questions