download file, without saving in server

Posted by lolalola on Stack Overflow See other posts from Stack Overflow or by lolalola
Published on 2010-04-26T13:27:27Z Indexed on 2010/04/26 14:53 UTC
Read the original article Hit count: 223

Filed under:
|

Hi,

Or possible for users to download the file without saving it on the server? I am getting data from the database, and I want to save them .doc (MS Word) file.

if(isset($_POST['save']))
{   
$file = "new_file2.doc";
$stringData = "Text text text text...."; //This data put in new Word file

$fh = fopen($file, 'w');    
fwrite($fh, $stringData);
fclose($fh); 

header('Content-Description: File Transfer');
header('Content-type: application/msword');
header('Content-Disposition: attachment; filename="'.$file.'"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);    
unlink($file);
exit;

}

How should the code look like without this: " $fh = fopen($file, 'w');
fwrite($fh, $stringData); fclose($fh);" and this "unlink($file);"

I hope to understand what I need enter code here

© Stack Overflow or respective owner

Related posts about php

Related posts about header