Hi,
I have a form that when submitted, inserts a new record into a MySQL database, and also uploads files (up to 5 jpegs). The images are uploaded to the correct directory, and there is file path information stored as META data in the database, so when I view the record with the coreesponding images, they are viewd. i.e. the images are held outside the DB, just the path is stored.
as the DB gets more mature, there is a possibility that the filename already exists, and while I check for an existing file of the same name, I just return a failed message for that jpeg.
What I would like to do, is start again - but have an autonumber method, where I upload 5 images, the first will then be renamed to 00000001.jpg and then so on and so forth.
THE PROBLEM I know how to check for if file_exists(), then do something....
so is it the correct approach to do the following
i) upload file to tmp location
ii) starting at 0000001.jpeg check if file exists
iii) keep counting until file does not exist
iv) copy file from tmp to desired location with filename 00-first-free-number.jpeg
v) unlink tmp file
I ask if this is the correct idea becuase, once there is a 1000 or so images, it'll have to count through a for loop until it finds the first free number, thus taking longer and longer each time.
any ideas? or should I just take the last entry from the db and then add 1 then carry on?
any ideas? or anything wrong with the ideas?
(I am still new at this) I'm not after code, just ideas.
regards