2
I need to transform a BLOB file that comes from a MYSQL database to the Image type, to use on my site, I need to do the conversion using PHP, when I use the image in BLOB format, it goes to the entire site in binary.
2
I need to transform a BLOB file that comes from a MYSQL database to the Image type, to use on my site, I need to do the conversion using PHP, when I use the image in BLOB format, it goes to the entire site in binary.
2
There are two ways, one is to save the binary in file (which is not interesting) and another is to add to src
tag img
informing that it is a binary. To do this, just add data:image/jpeg;base64,
followed by binary code.
That is to say:
<img src="data:image/jpeg;base64,<?= base64_encode($binary) ?>" />
Depending on how you saved (in rare cases) the base64_encode
may be omitted
Browser other questions tagged php mysql image type-conversion blob
You are not signed in. Login or sign up in order to post.
Keep bringing me the binary image.
– Roberto Albino
If binary code is appearing, there is something wrong with its implementation. Using the above code, if the image cannot be displayed, it should display the "broken image" icon and not the binary code. Make sure there is no quote that might be breaking the tag
img
– Gabriel Heming
It’s like @Gabrielheming said, using the img tag you had to see at least one broken image. But there is a caveat, for his reply, you will use "image/jpeg" if you know what the image format is? also has to know if the data has not already been saved as Base64, in this case would not need to use the function
base64_encode
.– Vinícius Fagundes
The photo is jpeg and was saved with the following Insert :Insert into FOTOS_PRODUTOS (id,image) values (3,LOAD_FILE('/opt/lampp/htdocs/mvp/images/Prod-top/terceira.jpg'))
– Roberto Albino
Checked the generated HTML to check if there is no, or missing, character?
– Gabriel Heming
how can I do this conference?
– Roberto Albino