我正在使用一个按钮来指向一个创建文本文件的脚本:
<?php $handle = fopen("file.txt", "w"); fwrite($handle, "text1....."); fclose($handle); ?>
字符串之后,我想Web浏览器建议下载或打开此文件,我该怎么办?谢啦,谢啦
3bygqnnd1#
使用readfile()和application/octet-stream标头
application/octet-stream
<?php $handle = fopen("file.txt", "w"); fwrite($handle, "text1....."); fclose($handle); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename('file.txt')); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize('file.txt')); readfile('file.txt'); exit; ?>
字符串
lskq00tm2#
$content = file_get_contents ($filename); header ('Content-Type: application/octet-stream'); echo $content;
字符串应该可以
2条答案
按热度按时间3bygqnnd1#
使用readfile()和
application/octet-stream
标头字符串
lskq00tm2#
字符串
应该可以