how can I display a pdf retrieved using file_get_contents in php?
I want to display, embedded in the HTML, a pdf file which is in a directory up to the document root.
Document root points to /var/www/web1/web and the pdf file is in /var//www/web1/docs/pdf, so I can't point it from the html.
I'm using PHP and I tried some suggestions like get_file_contents, base64_encode, .... but didn't worked.
All examples I find are to make download the pdf or to convert it into a jpg, but this is not what I need.
Simply load the pdf content by a php page, we call it
viewer.php, then embed the PHP page as it would be the document itself:
<embed src="viewer.php" width="80%" height="900px" />
In the viewer.php file:
<?php //Load file content $pdf_content = file_get_contents('../unreachable_file_outside_webserver.pdf'); //Specify that the content has PDF Mime Type header("Content-Type: application/pdf"); //Display it echo $pdf_content;
Otherwise another solution for bigger files (easier on RAM due to bufferized read/output without storing content in RAM) use
<?php header("Content-Type: application/pdf"); readfile("../unreachable_file_outside_webserver.pdf");
file_get_contents - Manual, This small function should show you how to address this issue: If you are using file_get_contents() function to retrieve HTTP url and printing HTTP content, you But when I want to display the pdf that also stored in my database I'm not able to do that. When I use this code this code show a small green piece of image but not the .pdf files. This code well works on image . But I'm not able to show .pdf files. can any help me to tell me where in my code I have to cahnge .
You can embed PDF on your website using a library, for example there's a great one called PDF.js
PDF is a binary format so you cannot exactly "display it".
Use the following html tag:-
<embed src="path_to_pdf_file.pdf" width="800px" height="2100px" />
php: how can I display a pdf retrieved using file_get_contents in php?, I want to display, embedded in the HTML, a pdf file which is in a directory up to the document root.Document root points to /var/www/web1/web The POST method provides support to send binary data like images, mp3 or pdf files, and also provides enhancement for file uploading to the server. When you submit a form through the POST method, PHP creates a $_POST associative array in this format, $_POST ['name as key'] to enable you to retrieve the form data.
You first need to go to root dir using "../"
<embed src="../docs/pdf/fileName.pdf" type="application/pdf" width="100%" height="500px" />
php file_get_contents of pdf not working in IE Solutions, I am using php to view pdf files through the web browser. The pdf file is stored outside of the root directory to deter direct linking (web page of pdf links requires [Editors note: As of PHP 5.2.1 you can specify `timeout` context option and pass the context to file_get_contents()] The only way I could get get_file_contents() to wait for a very slow http request was to set the socket timeout as follows.
Displaying Contents of a File Horizontally in PHP, PHP uses a function called "file_get_contents" to retrieve the content of a file. The contents are imported into a string, and that string is used to display the I want to display, embedded in the HTML, a pdf file which is in a directory up to the document root. Document root points to /var/www/web1/web and the pdf file is in /var//www/web1/docs/pdf, so I can't point it from the html. I'm using PHP and I tried some suggestions like get_file_contents, base64_encode, . but didn't worked.
PHP, How to Upload Image into Database and Display it using PHP ? The file_get_contents() function in PHP is an inbuilt function which is used to read a file into a It should just be a case of querying the DB and putting the PDF contents into a variable, then you can use the [fphp]file_put_contents[/fphp] function to write it to a file: file_put_contents
file_get_contents() and file() – Hacking with PHP, The next evolutionary step up from readfile() is just called file_get_contents(), and also takes one parameter for the filename to open. This time, however, it does How to read Content from PDF and Word Document files using PHP? I got this question while working with one of interesting PHP project so got in mind to share my solution. Basically my task was to get content from PDF or Word Document file and store into the mysql database.