I have a php page which outputs an .odt file printing data retrieved from a database.
I use the method below to create the .odt file:
header('Content-Type: application/vnd.oasis.opendocument.text');
The only problem I am experiencing is with <img> tag. The following command is ignored and no pictures appear on my .odt file:
<img src="/path_to_images/my_image.png">
I have tried using both the relative and the absolute paths to point to the image.
The answer suggested by uri2x worked just fine.
In conclusion, the full URL enables the image to appear on the .odt file:
<img src="http://example.com/path/image.png">
Related
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.
Any suggestions?
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 readfile
<?php
header("Content-Type: application/pdf");
readfile("../unreachable_file_outside_webserver.pdf");
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" />
You first need to go to root dir using "../"
<embed src="../docs/pdf/fileName.pdf" type="application/pdf" width="100%" height="500px" />
I have been trying to change the images in the WampServer Index.php File... When I looked at the Index.php File I saw something Interesting. The File its self was containing the Image in the RAW format. Latter in the Code the PHP Script Calls the Image using the URL like http://localhost/index.php?img=pngFolder called a Image file stored RAW in the PHP file as a png.
Here is a link to a website that has the index.php code...
Link
I would Like to know how to replicate this same process to work for other images. Granted the File will be larger but its a Price to pay for what I am doing for a project. The Reason I want some help with this is so I can do it correctly. I have Tried 2 times already. I managed to get it to call one image correctly but not some of the others. I'm not sure if the image is just a different encoding or what..... Any Help would be Appreciated.
They are using BASE64 to encode the images into text. You can google for a base64 encoder that will convert your images to text. You can then put the text directly in an <img src="..base64 text.." />
Here's one..
https://www.base64-image.de/
As far as getting the image from the url index.php?img=pngfolder..
You could put this at the top of the file
if(isset($_GET['img'])){
echo "...base64 string.."; exit;
}
Then you can use the index url as the src for your image and it will simply retrieve the base64 image
I uploaded the .doc file using php code and saved it in a folder ,the path is stored in database.
When i tried to make a view of the doc file in a div ...a dialog box appears asking whether to save or openwith ..
I'm using wampserver ....I just tried like this
<iframe name="awindow" frameborder=2 width=580 height=440 src="www/siva_example/pdf/1_siva.doc"></iframe>
Any help regarding..
Is it possible to view .doc file in browser or i have to convert it to pdf format...
It's not possible to display a .doc[x] in HTML. You can try to convert the .doc[x] to HTML or to an image.
you can view doc file by adding this to your header at request time
<?php
header('Content-disposition: inline');
header('Content-type: application/msword');
// not sure if this is the correct MIME type
readfile('MyWordDocument.doc');
exit;
You could try using google docs for this, use the below code, it works perfectly for ppts, have not been able to test it for a doc yet
<iframe src="http://docs.google.com/gview?url=http://yourdomain.com/document.doc&embedded=true" style="width:550px; height:450px;" frameborder="0"></iframe>
Ofcourse you would have to update the url as per your program using PHP
I have built my website in a way so that the actual database files are positioned as follows
root/
root/httpdocs <- public folder
root/databasefolder/actual_files_here/some_photo.jpg
How can I implement so that the php can view/load a photo from that databasefolder and echo it with tag. I simply tried "../databasefolder/" in a tag, but it doesn't work (of course it doesn't), since it's from hidden folder.
I tried Base64 which works in other browsers, but not with Internet Explorer, due to that silly kb limit.
In your HTML:
<img src="image.php?image=some_photo.jpg" />
And a php script that echoes your image.
header('Content-type: image/jpeg');
echo imagejpeg('root/databasefolder/actual_files_here/' . $_GET['image']);
You can use the get parameter "image" to load whatever image you need from that folder.
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)?
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
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 :
header('Content-Type: image/jpeg');
$img = LoadJpeg('bogus.image');
imagejpeg($img);
imagedestroy($img);
from http://php.net/manual/en/function.imagecreatefromjpeg.php example.
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.
Two things you can do:
Just link to the .pdf/etc. location on your server
Save the image of it as a .jpg and display that then put a link to download the pdf/whatever