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
1 Answer
Reset to default 2This 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