lindylex Posted February 21, 2008 Share Posted February 21, 2008 I am working on creating a php photo gallery. The problem I have is when a user uploads a file with the same name I would like to write the file and not overwrite the previous. What would be an elegant way to solving this problem? I assume some type of unique naming for the duplicated file. Can someone give a nice suggestion? Thanks, Lex Quote Link to comment https://forums.phpfreaks.com/topic/92333-uploaded-file-same-name-collision-solution/ Share on other sites More sharing options...
rhodesa Posted February 21, 2008 Share Posted February 21, 2008 What I normally do is store the file as the unique ID number from my table of photos. And, if I really care about the name of the file, store the filename in the table. That way the files will never collide. Quote Link to comment https://forums.phpfreaks.com/topic/92333-uploaded-file-same-name-collision-solution/#findComment-473076 Share on other sites More sharing options...
lindylex Posted February 21, 2008 Author Share Posted February 21, 2008 rhodesa, When some remove the image from the table how does the datase handle the next file? I assume the id is a sequence of numbers like id 0 = 1st image id 1 = 2 nd image when you delete id 0, 1st image, then what will be the id of the next photo uploaded? Thanks, for the quick reply? Lex Quote Link to comment https://forums.phpfreaks.com/topic/92333-uploaded-file-same-name-collision-solution/#findComment-473119 Share on other sites More sharing options...
Ken2k7 Posted February 21, 2008 Share Posted February 21, 2008 rhodesa, When some remove the image from the table how does the datase handle the next file? I assume the id is a sequence of numbers like id 0 = 1st image id 1 = 2 nd image when you delete id 0, 1st image, then what will be the id of the next photo uploaded? Thanks, for the quick reply? Lex Hello, The next photo can be id2 It doesn't matter how you number them. You can go up to 1000000 (a million) if need be. But it doesn't matter. So if id0 is missing, then the link would just not work. It's fine. Ken Quote Link to comment https://forums.phpfreaks.com/topic/92333-uploaded-file-same-name-collision-solution/#findComment-473125 Share on other sites More sharing options...
craygo Posted February 21, 2008 Share Posted February 21, 2008 Any rows that are deleted will delete the id number and NEVER use it again next insert will always be the next number after the last insert so if you have id 146 147 148 you delete 147, the next insert will still be 149. Even if 148 is deleted next the insert will still be 149. The counter is kept track of internally. ray Quote Link to comment https://forums.phpfreaks.com/topic/92333-uploaded-file-same-name-collision-solution/#findComment-473128 Share on other sites More sharing options...
rhodesa Posted February 21, 2008 Share Posted February 21, 2008 lindylex, are you not familiar with the AUTO_INCREMENT property in MySQL? Quote Link to comment https://forums.phpfreaks.com/topic/92333-uploaded-file-same-name-collision-solution/#findComment-473134 Share on other sites More sharing options...
lindylex Posted February 21, 2008 Author Share Posted February 21, 2008 "lindylex, are you not familiar with the AUTO_INCREMENT property in MySQL?" rhodesa, now I am thanks. Thanks, craygo, Ken2k7 and rhodesa Quote Link to comment https://forums.phpfreaks.com/topic/92333-uploaded-file-same-name-collision-solution/#findComment-473156 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.