Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

images, file based storage or db storage

Status
Not open for further replies.

kaptlid

Technical User
Nov 26, 2006
86
US
I have a question, I am going to start work on a project that will have alot of images stored on the server, give or take 1 million photos that have a max file size of about 300k.

What I am torn about is how to store them. Should they be stored on the web server as files, or inside the database. [assume mysql]

I am not sure what the advantages or disadvantages to each method is.

Regards,
 
IMHO, I suggest you store them in the file system, and only keep a link to them in the DB. Its easier to manage, and you can back up the images or alter them without having to go through the DB to do it.

Also the amount of code needed to reproduce an image from the DB in a web page is substantially bigger that the amount of code needed to link to them in the file system from the same web page.







----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Agreed with vacunita.

The page loading is faster in case of file location pointer which is mere text Vs blob which stores the entire image in database. Also it is easier to maintain and backup the databse.

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
I agree too, but those following the rather long vista development cycle will not the irony in the fact that MS wanted to use SQL to replace the file system (and i believe still plan to)

probably wouldn't have any effect on the php coding but the other arguments about file corruption v database corruption etc might lose their shine.
 
In terms of concurrent users, is file system still better than db, and does the operating system matter? I dont think it should matter in terms of OS. But then that brings me to my next question. How would you organize the directory structure especially if you have alot of users.

Thank you for your responses.
 
In terms of concurrent users, the file system will always be faster than the DB. The DB has to get a query, process it, pull out the relevant blob, and send it back. The file system just points to it. and the browser pretty much does the rest.

As for directory structure, it depends on what you need. Is each user going to have a folder with images? Are you going to separate it by date? etc...



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
As for directory structure, it depends on what you need. Is each user going to have a folder with images? Are you going to separate it by date? etc...

I wanted each user to have their own folder, with each album having its own directory, so something like:
apache/htdocs/members/username/album

 
Well then yes, that structure works fine.

you can pull out the user name or user Id from the Db and use it to construct the Paths to the images of the user in question dynamically.

something like:

$path="./apache/htdocs/members/" . $usernamefromDB . "/album";

And you can then use something like [blue]glob()[/blue] or [blue]opendir()[/blue], to get the contents of the directory. So you can show the first level, and then recurse to show deeper levels when the folders are clicked on.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
One more question. Is there a limit to how many directories can be inside a directory in windows or linux? So in case I have 100,000 members am I going to have 100,000 directories inside of the members folder?
And does that slow down file system access time?

Regards,
 
Is there a limit to how many directories can be inside a directory in windows or linux?
You get a appropriate answer for that in respective forums.
But having 100,000 directories sound too much for me :)



--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top