最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to embed PDF file into iframe using php - Stack Overflow

programmeradmin3浏览0评论

I have simple PDF file in my directory and I use fopen to open PDF file. When I try to embed it on into html iframe, the file is not showing up. I know I can specify the source as iframe attribute but I want to do it using 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>

I have simple PDF file in my directory and I use fopen to open PDF file. When I try to embed it on into html iframe, the file is not showing up. I know I can specify the source as iframe attribute but I want to do it using 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>
Share Improve this question asked May 30, 2017 at 21:21 user4564280user4564280 4
  • You are mixing 2 very different things here. fopen of php returns the contents of the file but iframe src expects a url. – Nawed Khan Commented May 30, 2017 at 21:23
  • Why are you needing PHP if you already have access to the URL of the PDF, why not just use the URL directly? – Peter Featherstone Commented May 30, 2017 at 21:24
  • @NawedKhan what is the alternative? I originally wanted to put path from local drive like c or network drive but I do not thing it will work so I'm experimenting with different methods. – user4564280 Commented May 30, 2017 at 21:25
  • @PeterFeatherstone I wanted to use the file from a network drive but after trying different methods of using file: with 3 and 5 back and front slashes and different binations it just does not seem to work in chromium, therefore I decided to try it with use of PHP. – user4564280 Commented May 30, 2017 at 21:29
Add a ment  | 

1 Answer 1

Reset to default 2

This should do the trick.

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

If the file is local you can put local file URL. But the file will not be accessible on internet. For example:

 file:///D:/WebDesign/HTML/test/file.pdf
发布评论

评论列表(0)

  1. 暂无评论