Page 1 of 1
Storing uploaded images - Database or folder?
Posted: Mon Jan 20, 2003 12:25 am
by senthil
Hi,
I want to allow uploading images in my website. I would like to know which is a better way to store the images. Is it better to store images in the database as a binary file or is it better to store the images in a folder and store a reference to it in the database? Or is there any other better way to store the images. If anyone can tell me the pros and cons of doing it either way, it will be very helpful.
Thanks
Senthil
Posted: Mon Jan 20, 2003 7:11 am
by Skywalker
It's better to stor images in to a folder and stor the path in the database.

Posted: Mon Jan 20, 2003 1:05 pm
by puckeye
Skywalker wrote:It's better to stor images in to a folder and stor the path in the database.

As pros and cons you can't beat that LOL
I prefer to use database to store the image for a few reasons.
1) you don't have to play with the folder's and file's permissions all you have to deal with is the database grant and you're OK.
2) when you manage those images it's easier to delete a bunch of images from a specific users with a database then on folders.
3) it's easier to defrag a database then a server HD... When you delete a few images you simply send an OPTIMIZE() command to your MySQL (MYASAM) table.
4) potentially a more secured way to display images because you don't have any other choice then using a PHP script to display the images... In that script there's nothing stoping you from placing a piece of code to check where the request is coming from and display the image only if the request comes from your server...
5) some hosting company don't count MySQL databases in the total HD space for their accounts. It's not "fair" but that's the way things are. Fortunately for my own ethical wellbeing my current host does count MySQL database in the total space I can use...
On the CONS side
1) if you have a lot of images it can slow your database while the same isn't true for files stored in folders, I'm not exactly sure at what point the performance degradation starts to show but so far I have a few hundred photos stored in my DB and it's still as fast as in the beginning.
2) data lost by a hasty command is a lot harder to cover then on the file system, unless you have a backup of your database before you manage the images your data is vulnerable to a wrong command (you didn't read your admin page correctly and pushed the wrong button...) On the file system you can always recover the files in a few ways (I'm not sure how to recover files so don't ask).
There are probably other PROS and CONS so if you have some I'd like to read them.
Posted: Mon Jan 20, 2003 3:20 pm
by senthil
Hi,
Thanks very much for ur replies. But after reading the replies, i'm more confused. :cry:
Puckeye, I will let u know if I come across anything useful.
Thanks
Senthil
Posted: Tue Jan 21, 2003 2:37 am
by twigletmac
Personally I find for simplicities sake that storing images in a folder and just referencing them in the database is easy when it comes to maintaining the images.
Why do you want to store images, maybe if we have a better idea of what you're trying to achieve we can offer more specific advice.
Mac
Posted: Wed Jan 22, 2003 1:09 am
by senthil
Hi,
I want the users to upload their items, whatever they have for sale. So, I need to store those images.
Right now, I'm storing in a database. I tried the program and it worked fine.
Thanks
Senthil