Finding a file where file extension is variable
Posted: Thu Jul 06, 2006 9:46 pm
I am developing a classified ads site where users are allowed to upload up to four photographs of the product they are selling. I have limited the uploads to gif's and jpeg's. Currently, I am working on a method for users to login to their account and delete a photo or replace an old photo with a new upload.
Initially, when the client uploads photos - the image files are renamed to the 7 digit ad id number with a 1,2,3 or 4 appended to it.
Example where advertisement id is 100293
1002931.jpg
1002932.GIF
1002933.gif
1002934.JPEG
Should the user choose to delete the image in the 1st spot (1002931.jpg), I will renumber all of the other images so that they move up one spot. Below is what the file names would look like if the client deleted image #1:
1002931.GIF
1002932.gif
1002923.JPEG
My problem is that I am having problems making the script fool proof. Is there a way to search for a file NOT by the file name and extension, rather by simply the filename prior to the extension?
Can I search to see if file 1002923 exists and then determine what the extension is?
I don't want to have to create an array which stores all of the possible file extension names (i.e. jpg, jpeg, JPG, JPEG, gif, GIF, Jpg, Jpeg, Gif, etc.)
Hopefully it is clear what I am asking, it is a bit confusing for me to put into words. Thanks.
Regards,
Cody Singsaas
Initially, when the client uploads photos - the image files are renamed to the 7 digit ad id number with a 1,2,3 or 4 appended to it.
Example where advertisement id is 100293
1002931.jpg
1002932.GIF
1002933.gif
1002934.JPEG
Should the user choose to delete the image in the 1st spot (1002931.jpg), I will renumber all of the other images so that they move up one spot. Below is what the file names would look like if the client deleted image #1:
1002931.GIF
1002932.gif
1002923.JPEG
My problem is that I am having problems making the script fool proof. Is there a way to search for a file NOT by the file name and extension, rather by simply the filename prior to the extension?
Can I search to see if file 1002923 exists and then determine what the extension is?
I don't want to have to create an array which stores all of the possible file extension names (i.e. jpg, jpeg, JPG, JPEG, gif, GIF, Jpg, Jpeg, Gif, etc.)
Hopefully it is clear what I am asking, it is a bit confusing for me to put into words. Thanks.
Regards,
Cody Singsaas