i am suggesting a different approach:
don't bother storing the filename. just use the primary key value from the table as the filenames. let's say Tom is user #28 from our user table. he uploaded 5 photos over the last week. the data might look like:
PicID | userID | date_time | Title
1 | 28 | 2006-09-01 08:02:33 | Me at home
2 | 28 | 2006-09-02 11:02:33 | My friend
3 | 28 | 2006-09-02 22:05:00 | My dog
4 | 28 | 2006-09-03 15:02:18 | My City
5 | 28 | 2006-09-11 02:08:33 | My Car
there will be 5 photos in /uploads/ called 1.jpg, 2.jpg, 3.jpg etc...
now Tom deletes "My Dog". so then next time he goes to upload a photo we now know that he only has 4 photos because we run a query like this:
SELECT COUNT(*) FROM photos WHERE userID = 28
thus we know that he has not exceeded his 5 photo limit and upload proceeds and a new file and db row are added:
PicID | userID | date_time | Title
1 | 28 | 2006-09-01 08:02:33 | Me at home
2 | 28 | 2006-09-02 11:02:33 | My friend
4 | 28 | 2006-09-03 15:02:18 | My City
5 | 28 | 2006-09-11 02:08:33 | My Car
6 | 28 | 2006-09-12 08:05:00 | My Cat
and the file 6.jpg is uploaded to /uploads/
after uploading that new photo he goes to upload another. when we run that same query we know that he has reached his 5 photo limit so we display an error saying "you have reached your limit. you must delete existing photos before you can upload any more". perhaps we can suggest that he delete "Me at home" since that is the oldest row in the db.
make sense?