php在线预览word,txt,xls文件,怎么做

发布网友

我来回答

4个回答

热心网友

第一种 预览

$file = fopen($path,"r"); // 打开文件
// 输入文件标签
Header("Content-type: application/pdf");
// Header("filename:" . $file_name);
// 输出文件内容
echo fread($file,filesize($path));
fclose($file);

第二种下载

Header("Content-type: application/pdf");// 文件将被称为 downloaded.pdf
header("Content-Disposition:attachment;filename='downloaded.pdf'");readfile($path);
第三种预览
Header("Content-type: application/pdf");// 文件将被称为 downloaded.pdf
header("Content-Disposition:inline;filename='downloaded.pdf'");readfile($path);
第四种下载
$file = fopen($path,"r"); // 打开文件
// 输入文件标签
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length: ".filesize($path));
Header("Content-Disposition: attachment; filename=" . $file_name);
// 输出文件内容
echo fread($file,filesize($path));
fclose($file);

热心网友

$path = '***.txt';

$content = file_get_contents($path);

<div><?php echo $content;?></div>追问txt的本身浏览器就可以读取,关键是doc的怎么直接预览?

热心网友

打开文件读取呗,然后输出追问读取还是弹出保存窗口,不是可以直接在浏览器看到。

热心网友

二进制文件打开 fopen追问能说的详细点不?或者有实例不?

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com