或者用户可以下载文件而不将其保存在服务器上?我从数据库中获取数据,我想保存它们.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;
Run Code Online (Sandbox Code Playgroud)
}
如果没有这个代码应该怎么样:"$ fh = fopen($ file,'w');
fwrite($ fh,$ stringData); fclose($ fh);" 这个"unlink($ file);"
我希望在这里了解我需要的输入代码
| 归档时间: |
|
| 查看次数: |
1532 次 |
| 最近记录: |