Display Blob images

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

  1. 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.

    0
    1. jordane45 Posted messages 30426 Registration date   Status Moderator Last intervention   4 830
       

      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!

      1
      1. Lud0o8 Posted messages 2 Status Member > jordane45 Posted messages 30426 Registration date   Status Moderator Last intervention  
         

        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.

        0
      2. yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   1 588 > Lud0o8 Posted messages 2 Status Member
         

        Is it the browser that needs to load multiple images "at the same time"? What is the size of an image?

        0
      3. jordane45 Posted messages 30426 Registration date   Status Moderator Last intervention   4 830 > Lud0o8 Posted messages 2 Status Member
         

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

        0