简体   繁体   English

如何通过使用PHP在浏览器中显示最常用的文件(pdf,doc,docx,xl​​s等)?

[英]How to display most used file (pdf, doc, docx, xls, …) into a browser by using PHP?

I need to display a (pdf,doc,docx,txt) documents inside an php web form with the ability to select a part of the document content and do some processing on it in the right click (like saving the selected content to DB)? 我需要在php Web表单中显示一个(pdf,doc,docx,txt)文档,并能够选择文档内容的一部分并通过右键单击对其进行一些处理(例如将所选内容保存到DB) ?

I try this way :- 我这样尝试:-

<iframe src="http://docs.google.com/viewer?url=<?=urlencode($docx)?>&embedded=true" width="600" height="780" style="border: none;"></iframe>

But is show me as html 但显示为html

PHP can set the header information for a file and so you can display anything as file.php, loading the file.php you can then specify what it should be handled as- for example you can generate an image and output it as a jpeg file : PHP可以设置文件的头信息,因此您可以将任何内容显示为file.php,加载file.php,然后可以指定应处理的内容,例如,可以生成图像并将其输出为jpeg文件:

header('Content-Type: image/jpeg');
$img = LoadJpeg('bogus.image');
imagejpeg($img);
imagedestroy($img);

from http://php.net/manual/en/function.imagecreatefromjpeg.php example. 来自http://php.net/manual/en/function.imagecreatefromjpeg.php示例。

Using a similar method for setting the header content-type you can output PDF contents or DOC or whatever, by setting the header to the correct file type and loading the contents of the file with PHPs file_get_contents() ( http://php.net/manual/en/function.file-get-contents.php ) function, and outputting that to the browser / iframe. 使用类似的方法用于与脉动热管设置报头的内容类型可以输出PDF内容或DOC或什么,通过将报头添加到正确的文件类型和加载文件的内容file_get_contents() http://php.net /manual/en/function.file-get-contents.php )函数,并将其输出到浏览器/ iframe。

Two things you can do: 您可以做两件事:

  1. Just link to the .pdf/etc. 只需链接到.pdf / etc。 location on your server 服务器上的位置

  2. Save the image of it as a .jpg and display that then put a link to download the pdf/whatever 将其图像另存为.jpg并显示,然后放一个链接以下载pdf /其他

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM