You are here: Re: Where to store pictures, in DB or in files? « PHP Programming Language « IT news, forums, messages
Re: Where to store pictures, in DB or in files?

Posted by David T. Ashley on 07/07/06 21:29

"Richard Levasseur" <richardlev@gmail.com> wrote in message
news:1152301909.936208.193410@m79g2000cwm.googlegroups.com...
>
> romayankin@gmail.com wrote:
>> I'm making some kind of news-board site on PHP (tthat's why I guess
>> it's the right place to post the question here). Each entry would
>> have a small picture (less then 100kb). Taking into consideration all
>> pros and cons the question is where to store these pictures in DB or in
>> files?
>
> Files. You can link to them in an <img> tag easier, don't have to
> write code to extract the image and send the appropriate headers, and
> can easily view/modify/ them using ftp/samba/etc. Store a path to the
> file in the database instead.

Depending on how many files you plan to accumulate, it is traditional to use
a directory structure where you keep the file in a directory whose path
components are the file index moduli of different prime numbers. For
example, choose 2, 3, and 5 as the prime numbers, then

File #1 goes in 1/1/1/1/filename.
File #2 goes in 0/2/2/2/filename.
File #3 goes in 1/0/3/3/filename.
File #4 goes in 0/1/4/4/filename.
File #5 goes in 1/2/0/5/filename.
File #n goes in (n mod 2)/(n mod 3)/(n mod 5/n/filename.

As long as you choose different prime numbers, you won't get the same hashed
directory until a period which is the product of the primes.

The moduli are cheap to compute for a computer.

Files are the superior way. In addition to all other advantages, if
something goes monstrously wrong on the server or in the database product,
the files can be recovered separate from the database.

Dave.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация