On Jul 3, 2007, at 10:38 AM, Clinton Gormley wrote:
I didn't mean: stick the file in the DB.
I meant, stick the file into a directory on a particular machine, and
then put this into the DB:
Sorry - I meant, store this in the DB:
- ID: 1234
- type: image/jpeg
- path: 12/34/1234.jpg
- server: images1.domain.com
So that your program would construct a URL pointing to the correct
server, or a translation layer would forward the request to the
correct
server
i always do that... metadata in db and file on os
if you expect a large amount of files, you should do hash the file
name and store in buckets
ie
$name= 'file'
$hash= md5($name);
$path= sprintf( "/%s/%s/%s/%s" , $root, substr($name,0,2), $root,
substr($name,2,4),$name );
you can't store by name alone because of character distribution among
english words and numbers -- you'll end up with buckets that have 20k
files and others that have 1. md5 will give you a good distro in 32
chars ( or bump to a higher base and show it in 16chars !)
if you're doing actual numbers, put in buckets working backwards --
ie, by the power of 1,10,100 etc, and not reading frontwards. you'll
get more even distribution that way.
these are 2 mathematical principles... i can't remember their names.
but they are good reads if you can find the names. the irs uses the
latter one for tax audits.
also keep in mind the os performance with files. most os's do the
best at ~1k files per directory; some are good up to 5k
md5 with base16 can give you a 3 deep directory \d\d\d = 16*16*16 =
4096 files
md5 with base32 can give you a 2 deep directory \d\d = 32*32 = 1024
files
md5 with base64 can give you a 2 deep directory \d\d = 64*64 = 4096
files
if only base32 were more common.... thats a good sweet spot. for
simplicity, i usually do 3 base16 chars. but 2 base32 might be
better for your os.
// Jonathan Vanasco
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
| CEO/Founder SyndiClick Networks
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
| Founder/CTO/CVO
| FindMeOn.com - The cure for Multiple Web Personality Disorder
| Web Identity Management and 3D Social Networking
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
| RoadSound.com - Tools For Bands, Stuff For Fans
| Collaborative Online Management And Syndication Tools
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -