【发布时间】:2011-02-12 09:57:00
【问题描述】:
或者用户可以下载文件而不将其保存在服务器上? 我正在从数据库中获取数据,我想将它们保存为 .doc (MS Word) 文件。
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;
}
如果没有这个,代码应该如何:
" $fh = fopen($file, 'w');
fwrite($fh, $stringData);
fclose($fh);"
还有这个“unlink($file);”
我希望了解我需要什么 在此输入代码
【问题讨论】: