phpsqlmysqlphpmyadmin

How to store image files in the backend of a site


I'm building a site, and have just started getting into developing the backend.

The point of my site will be to display images to a visitor. For development purposes, I'd like to test everything first before going live.

I'd like to know what the best way of storing these images is. I've just finished setting up my Wamp server, and added a new db with phpMyAdmin. I found that I can store each image directly in the mySQL database as a BLOB data type. But is this the best way to go?

Thank you!


Solution

  • This is most certainly not the way to go. You will then need to keep the blob in memory in PHP before sending it to the browser.

    A better approach would be to store the images as files in the filesystem and just store the filename in your database. that way, you can offload the entire image serving to the web server and never involve PHP in the HTTP requests for the file.