Display Blob images
jordane45 Posted messages 30426 Registration date Status Moderator Last intervention -
Hello,
First of all, I am just starting with PHP, I have my MySQL database, I can connect to it and extract my IDs, names, etc. well...
I have stored images as BLOBs in my database and I would now like to display them, the problem is I have no idea how to do that. I spent my morning looking for a solution on the web but I am stuck. I have already managed to display the BLOB code (?) on my page but I can’t see the image.
I read somewhere that there are more optimal ways to store and use images for a website, so if you have any information I would be grateful.
Thank you in advance.
2 answers
-
yg_be Posted messages 23437 Registration date Status Contributor Last intervention Ambassadeur 1 588
Hello,
"Optimal" depends on the context. Some choose to store images in files, outside of the database.
-
Hello,
Storing images in the database is, in any case, a very bad idea....
It takes up a lot of space in the database... (which can slow it down considerably) and above all... storage is more extensive in terms of "site files" than in the database...
Therefore, it is better to prioritize storing files in a directory on the site and only store the path to it in the database!
Thank you for the response,
So if I understood correctly, I store all my images in a directory. Is that going to slow down the site?
Actually, I have a site that fetches a random image using js every time a button is clicked; the fact that all images need to load at the same time considerably slows down the site, that's why I tried to look for solutions.
The fact that all images must load at the same time significantly slows down the site, that's why I tried to look for solutions.
You shouldn't load them all... because otherwise... yes... it will slow down your site.
In your JS code, just modify the SRC attribute of the <img> element that will display the image....
Your JS will only contain the "path" to the images to display... it won't take any "loading time".
-
-
yg_be Posted messages 23437 Registration date Status Contributor Last intervention Ambassadeur 1 588
Did you really search for an entire morning? I found this in a few seconds: https://forums.commentcamarche.net/forum/affich-34583830-afficher-une-image-blob