in reply to sequencial file naming

Just a suggestion here... if you do not need the file names sequence to be gap-free, but nearly want them to be sequential, I suggest you use the epoch date (number of seconds since some time in the long, long past.

Next, you check that the file does not exist, and use that ID. If it exists, increment by one, and check again.

The upside is that unless you average 1 request per second, you're safe.

The downside is that the filenames are ugly.

On the command line, trz it with this: perl -e 'print "time()\n"

Hackmare