How to display all files from blob mysql (image, txt, pdf) - php

I display an images from the database like that:
$file = '<a class="" href="data:image/jpeg;base64,' . base64_encode( $rows['file']) . '">link</a>';
I'm looking for a way to display all types of files (.txt, .pdf, etc…) from the database.

For each link, you can get the file extension first and then use a different method of displaying each file type appropriately. For example, you can use the FPDF file view to open all .pdf links and for .jpeg links you can just load the base64 into the url. If you are trying to view a .txt or other plain text file type, you can simply echo or print the file into the browser. For PDF's, there is no real way to just echo it to the browser so you will either have to figure out how to render it on your own or use something like FPDF.

Related

PHP::Imagick Creating a Temp FIle from A Composite Image, for displaying through <img> Tag

Is it possible to create a temp file server side for viewing an image?
I've some images & they're displayed from server but I want to have them watermarked... Found out about the Imagick Class, used composite... It can be viewed when sent as header but I need it somehow visible for the tag.
I don't want to uses 'write image' & create a new image from the composited image. I'm trying to use it as client Side thing (I'm not familiar with JS... Yes, I'll look into it but need an alternative till then).
Another alternative that I'm aware of is I should control that WHILE uploading the images but I've already uploaded quite a few so...
Any help appreciated!
Have you tried using the function that generates your image as a src attribute for the <img /> tag?
I don't know exactly how your code is, but I am thinking the end result could be something like:
<img src="data:image/jpeg;base64,<?php echo base64_encode($image_headers); ?>">
You basically output the headers inside the image src as a base64 encoded string.
What you should keep in mind is that you should adjust the image/jpeg type to the corresponding type of your image.
For example:
For JPG, JPEG files it would be image/jpeg
For PNG files it would be image/png
For WEBP files it would be image/webp
And of course the encoded string should be an image of the corresponding format.

Extract data(both text and images) from Image file

I have a PDF file(Content as image in PDF), i need to extract text and images from the PDF file. I have tried PDF converter libraries in Laravel, but none is worked. So i have converted that PDF into image with Imagick, after that using TesseractOCR extracting the text from the Image(jpg format), now i need to extract images aslo. Is there any possibility extract both text and image from Image.
My PDF is like below
I have tried TesseractOCR library in laravel, now i'm able to extract the text successfully.
$file = public_path().'/images/S29A57P1-4.jpg';
echo (new TesseractOCR($file))
->lang('eng')
->run();
I want to extract both text and images from PDF or Image.

Storing Images In a PHP File

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

print image on odt file using php

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">

How to display most used file (pdf, doc, docx, xls, …) into a browser by using PHP?

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

Categories