Hi Scott,

Yes I am suggesting the naming of the image file by ascending number (at
least in part - our Sony digicam produces files named DSCnnnnn.JPG). The
danger of generating a filename by hash is that collisions are always
possible. Moving to an 'accession number' removes that threat.

The choice of locating the file in one or more sub-directories is a separate
issue. After all, you could have one field in the db to keep track of the
image's filename and another to keep track of its location - the two may or
may not be related.

Related: you can number/name the file and then use the last digit to
determine which directory to locate it within (10 directories) - or the last
two digits (100 directories). This has the advantage of spreading the
directory/index load evenly as new images are 'accessioned'/arrive into the
system.

Non-related: you can use whatever algorithm you like, eg hashing or
randomising, to decide where to place the image file. A low level of
'collisions' is immaterial in this application (whereas it would be
catastrophic for image filenames)!

Regards,
=dn


> So what you are suggesting is using an AUTO_INCREMENT field, possibly the
> image's Primary Key as an identifier
> for that image file., which is fine by me, but surely one should store
files
> across directories, as 10000 images
> in a single directory might slow down access to those images in the
> filesystem, or not so?
>
> Thanks for your input.
>
> Regards
>
> -Scott
>
> > -----Original Message-----
> > From: DL Neil [mailto:[EMAIL PROTECTED]]
> > Sent: 21 August 2002 04:31
> > To: [EMAIL PROTECTED]; Bogdan Stancescu
> > Subject: Re: [PHP] Image library
> >
> >
> > Scott (confirming Bogdan),
> >
> > Libraries of all types have had this concern for years - even though
books
> > are uniquely identified by ISBN, that is still not good enough for
library
> > purposes (eg multiple copies of a single title). So they, exactly
> > as Bogdan
> > suggests, use an "Accession" number sequence - which can be
> > implemented very
> > neatly in MySQL (from PHP) as an AUTO_INCREMENT field.
> >
> > Regards,
> > =dn
> >
> > > I've seen this kind of random approach several times and I keep
> > > wondering why not counting the files instead. Yes, it may take a
little
> > > longer when uploading but I personally think the safety of the
approach
> > > is worth the insignificant speed sacrifice.
> > >
> > > Bogdan
> > >
> > > Scott Houseman wrote:
> > > > Hi all.
> > > >
> > > > This confirms what I suspected.
> > > >
> > > > The hash algrithm:
> > > >
> > > > I have a directory structure: dirs 0 - f, and within each of
> > these, the
> > same
> > > > dir structure 0 - f.
> > > > When an image gets uploaded into the library, do an md5sum of
> > the file,
> > take
> > > > the first 2 chars of that hash
> > > > and there's your path. e.g
> > > > $PICDBPATH.'/a/7/a7b8be10b0e69fe3decaa538f1febe84'
> > > >
> > > > I'm not sure what the mathematical randomness of this is, but I'm
sure
> > it's
> > > > pretty random, and the chances
> > > > of collision should be virtually null, the only time you should
> > overwrite a
> > > > file is if you upload the exact same file(?)
> > > > Is there a better way of doing this?
> > > >
> > > > Cheers
> > > >
> > > > -Scott
> > > >
> > > >
> > > >>-----Original Message-----
> > > >>From: Justin French [mailto:[EMAIL PROTECTED]]
> > > >>Sent: 21 August 2002 03:25
> > > >>To: [EMAIL PROTECTED]; PHP General
> > > >>Subject: Re: [PHP] Image library
> > > >>
> > > >>
> > > >>on 21/08/02 9:45 PM, Scott Houseman ([EMAIL PROTECTED]) wrote:
> > > >>
> > > >>
> > > >>
> > > >>>Which way would be the most efficient/fastest to access images
> > > >>
> > > >>from an image
> > > >>
> > > >>>library.
> > > >>>A) Store image files in a hash directory structure AND storing
> > > >>
> > > >>each file's
> > > >>
> > > >>>information in a mysql table
> > > >>>OR
> > > >>>B) Storing image information in mysql table AND storing the
> > > >>
> > > >>image in a BLOB
> > > >>
> > > >>>field in that table.
> > > >>
> > > >>>From all accounts I've read on this list, a database is not
> > > >>usually faster
> > > >>than a filesystem.  And for large amounts of files, like 1000's,
> > > >>a hash will
> > > >>speed it up more.
> > > >>
> > > >>
> > > >>
> > > >>>The way I see it, considerations to be taken into acount:
> > > >>>- Is it quicker/better to retrieve image from table & then stream
out
> > to
> > > >>>browser OR simply direct the browser to the file?
> > > >>>i.e <IMG SRC="/imagelib/image.php?iImageID=10"> OR <IMG
> > > >>>SRC="/imagelib/5/f/10">
> > > >>>- Will a database OR filesystem be more scalable i.e. which
> > wil perform
> > > >>>better when there are 10000 images in the libary?
> > > >>
> > > >>Filesystem should be quicker.  You need to think about how
> > you hash the
> > > >>files up for the most even spread of files in each directory I
guess.
> > > >>
> > > >>
> > > >>Justin



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to