tags:

views:

40

answers:

2

I have a folder full of 2000 images, all unique and named like this:

/images/0001.jpg (... 2000.jpg)

I need to be able to access 100 random, unique images. Something like this:

/sets/0001/001.jpg (... 100.jpg)

I need hundreds of "sets of unique images" like this.

I made one example set using a folder and a htaccess file with 100 lines like this:

Redirect 303 /sets/1234/001.jpg /images/0432.jpg
Redirect 303 /sets/1234/002.jpg /images/0391.jpg
...

How would this be done the easiest way without actually creating hundreds of folders and corresponding htaccess files?

Thanks a lot!

+3  A: 

Use a rewrite rule to direct /sets/*/*.jpg to a php script and have that file serve the images from the images folder. Store the already sent images in that set in a session so that you can make sure the image being sent in the current request is unique.

Sabeen Malik
A: 

Figure out a naming scheme for your images. For instance, you could stick them all in a folder name [1...2000].jpg

Then figure out a way to create U unique subsets (of size 100)

From there, you can do all sorts of things to serve the sets efficiently. Once you have a big list of random unique sets, you can programmatically generate rewrite rules, or whatever.

The tricky part, you'll find, is generating the sets themselves.

There was a question here on SO about that, which I drunkenly supplied PHP reference code for. You can read it here

timdev