download file, without saving in server
- by lolalola
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