Currently I do a:
//make any non-alphanumeric or dot characters a dash
ereg_replace("[^A-Za-z0-9.]", "-", $fileName);
(will be changing to pregmatch next rewrite)
//then I add a 1 or 2 or 3 onto the end, if that filename already
exists.
People seem ok with not putting non-english characters into the
filename, so this seems to work ok.
It would be an option to make the filename a number, although I would
rather just add the number onto the start of the name.
I can see how this would work with #1. I'm guessing I would need to
store the number somewhere (paramater in the database I guess) so I
can increment it, and the filenames are a bit less 'usable' if someone
needs to look at them, so it is not without it's downsides, although
these downsides are probably the smallest downsides out of the
possible options so far.
On Jan 18, 3:47 pm, Chris Hope <[email protected]> wrote:
> You'd need to do some amount of renaming anyway to get rid of spaces
> and other nasty characters.
>
> 2010/1/18 Jevon Wright <[email protected]>:
>
>
>
>
>
> > Do you need to keep "dogs.jpg" as the filename? What if you renamed it to a
> > number? Then plan #1 might work well.
>
> > Jevon
>
> > On Mon, Jan 18, 2010 at 3:23 PM, matt_thomson <[email protected]> wrote:
>
> >> Hi All,
>
> >> Thanks for the help with the last problem, I got another one I have
> >> been thinking about for a while, and can't come up with a good
> >> solution. Essentially it is how to organize up to tens of thousands of
> >> files in folders, so there isn't too many files in one folder, but the
> >> database knows where the files are, currently the situation is like
> >> this:
>
> >> 3 files, dogs.jpg, cats.jpg and birds.jpg get put in the "uploaded"
> >> folder, and 3 database records get written:
>
> >> id | gallery_id | filename
> >> 1 1 dogs.jpg
> >> 2 1 cats.jpg
> >> 3 1 birds.jpg
>
> >> The when the gallery with an id of one gets displayed, the images
> >> resized/dogs_600_800.jpg, resized/cats_600_800.jpg, resized/
> >> birds_600_800.jpg get made (800 by 600 are the max width and height
> >> settings for gallery 1).
>
> >> I also want to have a "copy gallery" function, which adds a row to the
> >> gallery table that is a duplicate of gallery 1, except it is called
> >> "copy of gallery 1" and has a new id. The copy gallery function would
> >> do this to the image table:
> >> id | gallery_id | filename
> >> 1 1 dogs.jpg
> >> 2 1 cats.jpg
> >> 3 1 birds.jpg
> >> 4 2 dogs.jpg
> >> 5 2 cats.jpg
> >> 6 2 birds.jpg
>
> >> Now I could change the width and height of gallery 2 to 400 and 300,
> >> and when gallery 2 gets viewed, resized/dogs_300_400.jpg, resized/
> >> cats_300_400.jpg, resized/birds_300_400.jpg get made.
>
> >> This all works great, until 10,000 images are added, and the
> >> 'uploaded' and 'resized' get so big they are not manageable if you
> >> want to ftp and find an image, and they will eventually slow the
> >> server down.
>
> >> Possible solutions I have so far:
> >> 1.)Make folders based on the first letter/number of the filename,
> >> splits the files into 36 folders (or 36x36 if first and second
> >> character).This is good as any row in the database knows where the
> >> uploaded file is (when it makes resized images), because it knows the
> >> filename. Downside: someone uploads thousands of images from a camera
> >> that lables the images dsc_0001, dsc_0002, dsc_0003....
>
> >> 2.)Make folders based on id in database. (eg 0-100 folder, 101-200
> >> folder). Good side, keeps right amount of images in folder. Downside,
> >> when you copy a gallery, the new records don't know where to look for
> >> the uploaded image.
>
> >> 3.)For every upload, check the size of the latest folder, and if it is
> >> too big, make a new folder. For every database record write the path
> >> of the image including the folder and file path. When image records
> >> are copied, this full path will get copied too. Downside, a lot of
> >> time working out the latest folder, and size of the folder each time
> >> you upload a file.
>
> >> Does anyone have any smarter ideas on how to organize the files?
>
> >> Thanks,
>
> >> Matt.
>
> --
> Chris Hope
> The Electric Toolbox Ltd
>
> Email: [email protected]
> Web:www.electrictoolbox.com
> Phone: +64 9 522 9531
> Mobile: +64 21 866 529
--
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[email protected]