No announcement yet.

Store images in MySQL?

This topic is closed.
  • Filter
  • Time
  • Show
Clear All
new posts

  • Store images in MySQL?

    I saw that vbulletin stores the attachments such as images in the MySQL Database, but how do you do that? And how do you display it?

  • #2
    I use a system of reading output of a uploaded file to put it into the db as base64encoded text. To display it, you simply set the header!


    • #3
      It should be noted that whilst this is good for management of images, it's very bad for bandwidth and the database.

      Because the avatars are served by avatar.php and a querystring dictates the avatarId... the querystring will prevent a browser, proxy or cache from storing a copy. So the browser will get images over and over again, not realising that it may have already been served that particular image.

      That part can be solved somewhat if you're on apache by the use of .htaccess files and mod_rewrite (read the apache docs, too much for me to go into here).

      Now... if the images are being served everytime, they are using up database resource and bandwidth. Both of which cost you in either cash (bandwidth) or forum performance (database).

      The best solution is to have your images on the docroot. This allows the web server to issue replies to browsers (telling the browser that it already has an image, and to use the cached version) to save bandwidth.

      Then you would merely manage the meta-date within the database.

      Another novel approach, is to store the images in the database, but to write the images out to the docroot when they are added or updated. This way you get all of the management stuff, but benefit from having static files that can be cached. Of course it is likely that you would still need to query the database to construct the path to the static images... but a query to return meta-data is much better than a query that returns, say, 50k of binary data.
      London Fixed-gear and Single-speed


      • #4

        La La Lol please enter your details as has been asked several times by the staff here.
        Scott MacVicar

        My Blog | Twitter


        Related Topics


        • stsjs
          Issues Uploading Images
          by stsjs
          Looking to get some assistance with an issue I'm experiencing in uploading images. When all the images are stored in the database, I can upload images from the hard drive no problem. However, I moved...
          Thu 23rd Apr '15, 8:47am
        • jstear
          Uploaded images not displaying
          by jstear
          Not sure when this started, but images are not longer displaying. We have images stored in the database and have since day one. Images were displayed before, but we noticed last night that they no longer...
          Tue 18th Nov '14, 8:40am