Biscuit128
Biscuit128

Reputation: 5398

Saving a blob to disk in php

I have a blob saved in my database (a text file). I can retrieve this and then use echo on the return value which prints the text file contents. However, I really am not sure how to save the file to disk

header("content-type: file/txt");

This seems to save the current php file to disk so I am guessing i need to modify this somehow to work with my blob? Is this correct?

Thanks

Upvotes: 1

Views: 1942

Answers (2)

ghstcode
ghstcode

Reputation: 2912

Do something like this:

header('Content-disposition: attachment; filename=blob.txt');
header('Content-Type: application/octet-stream');
readfile('...path to your file');

or

header('Content-disposition: attachment; filename=blob.txt');
header('Content-Type: application/octet-stream');
echo $blob;

That should force a download to the client.

Upvotes: 4

Andrew Leap
Andrew Leap

Reputation: 956

header('content-disposition: attachment; filename=test.txt');

Change the test.txt to the file's name

Upvotes: 0

Related Questions