如何使用PHP将PDF文件嵌入到iframe中

时间:2017-05-30 21:21:06

标签: javascript php html iframe fopen

我的目录中有简单的PDF文件,我使用fopen打开PDF文件。当我尝试将其嵌入到html iframe中时,该文件未显示。我知道我可以将源指定为iframe属性,但我想使用PHP来实现。

<?php
$myfile = fopen("http://ipaddress/file.pdf", "r") or die("Unable to open file!");
fclose($myfile);
?>

<body>
<iframe src="<?php $myfile; ?>#toolbar=0&navpanes=0&scrollbar=0" width="1000" height="1000"></iframe>
</body>

1 个答案:

答案 0 :(得分:2)

这应该可以解决问题。

<body>
<iframe src="http://ipaddress/file.pdf" width="1000" height="1000"></iframe>
</body>

如果文件是本地文件,则可以放置本地文件URL。但该文件无法在互联网上访问。 例如:

 file:///D:/WebDesign/HTML/test/file.pdf
相关问题