Hi all.
I've got some PHP code to store binary files in a MySQL database and to pull it out. Currently, clicking on the filename in my display page opens a new browser window which is generated by the following code:
new file;
$file = $db->getfile("filename.doc");
header("Content-Type: " . $file->Type . "");
echo $file->BinData;
The file is an object, as you can see, with internal variables Type and BinData. Type is a string containing the mime type of the file. BinData is the raw binary data. BinData is itself generated by some fopen and fread functions, and it's all good.
The problem I'm having is this... instead of asking me what I want to do with the file (Save or Open), as befits a Word document for example, it dumps it out into the new window, garbled as heck. I can get around this by right-clicking the filename and choosing Save As... then changing the filename and the filetype, but I'm building this for users who won't stand for it. Is there something wrong with my header code?
Also, I'd like, if possible, to make the browser automagically use a certain filename, instead of the php file that's generating the file. Is there an HTTP header I can send it, so the file transfer is totally transparent to users?
Many thanks,
Tudor