Using PHP include () function to include a png image

Well, people, despite the most famous practices, today I decided to do this:

<img src='<? include("dir/dir/img.png"); ?>'>

With 6 different .png images.

Unfortunately, only 2 out of 6 were clearly visible in the browser.

Why was only 2 of 6 images shown? Perhaps there was a bit of data bit on the way?

Thank you for your time:]

+3
source share
4 answers

This does not work because the srctag attribute <img>must not contain raw image data; rather, it should contain a URI that points to image data.

data: URI, (X) HTML-. , , Internet Explorer. , , IE8 32 URI data:.

PHP, :

<img src='data:image/png;base64,<?php echo base64_encode(file_get_contents("dir/dir/img.png")); ?>'>

image/png URL-, . , GIF, image/gif.

+11

.

( , HTML, URL), . data URI.

+5

include() PHP . , , <?, . readfile().

, Artefactos.

+3
source
< img src='< ?php echo 'data:image/png;base64,' . base64_encode(file_get_contents('dir/dir/img.png')) ; ?> ' >
+1
source

Source: https://habr.com/ru/post/1759234/


All Articles