joanna2008 Posted February 11, 2008 Share Posted February 11, 2008 Hi, I am creating a website which I would like users to sign up and upload a picture. My problem is: if a user signs up and uploads an image, I store the image path in the table and then another user signs up and stores an image with the same image name - when uploaded to the server the second image will overwrite the first image, correct? How can I avoid this? Thank you. :-\ Quote Link to comment https://forums.phpfreaks.com/topic/90453-duplicate-image-name-in-a-database/ Share on other sites More sharing options...
Northern Flame Posted February 11, 2008 Share Posted February 11, 2008 why not name the image the users username? because if every user has a unique username, and you name their image their username, then every image will have a unique name on your server. Quote Link to comment https://forums.phpfreaks.com/topic/90453-duplicate-image-name-in-a-database/#findComment-463718 Share on other sites More sharing options...
cooldude832 Posted February 11, 2008 Share Posted February 11, 2008 physical image names of uploaded images should never be what the original file name should be. It should be some sort of logical delimetered integer based system. Such as Username_ImageUplaodCount.jpg or UserID_ImageID.jpg So rename on upload and if you want that original file name store it in mysql. Quote Link to comment https://forums.phpfreaks.com/topic/90453-duplicate-image-name-in-a-database/#findComment-463719 Share on other sites More sharing options...
joanna2008 Posted February 11, 2008 Author Share Posted February 11, 2008 Thank you for your quick responses! Would it make sense to you that I create 1 table storing all user information and up to 3 image fields using unique ID names (as suggested previously) or should I create a new table if I would like to store more than one image? (Or does it not matter, at all?)Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/90453-duplicate-image-name-in-a-database/#findComment-463727 Share on other sites More sharing options...
Northern Flame Posted February 11, 2008 Share Posted February 11, 2008 do you expect your users to upload multiple images or only one? Quote Link to comment https://forums.phpfreaks.com/topic/90453-duplicate-image-name-in-a-database/#findComment-463729 Share on other sites More sharing options...
joanna2008 Posted February 11, 2008 Author Share Posted February 11, 2008 I would like for users to have the option of uploading up to 3 images. Quote Link to comment https://forums.phpfreaks.com/topic/90453-duplicate-image-name-in-a-database/#findComment-463743 Share on other sites More sharing options...
nethnet Posted February 11, 2008 Share Posted February 11, 2008 Since you're only allowing three images, and that is a relatively small amount, you could just contain that information in three fields in the users table. Quote Link to comment https://forums.phpfreaks.com/topic/90453-duplicate-image-name-in-a-database/#findComment-463744 Share on other sites More sharing options...
joanna2008 Posted February 11, 2008 Author Share Posted February 11, 2008 Thank you. Pls advise if I should be posting the following question as a new post. I am also looking to add the functionality of users being able to send messages to each other (private). Can you pls advise if I would need to set up a seperate table for this? IE. first table: nickname (primary) password image(s) etc. second table: fromnickname (foreign) tonickname msg etc. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/90453-duplicate-image-name-in-a-database/#findComment-463749 Share on other sites More sharing options...
teng84 Posted February 11, 2008 Share Posted February 11, 2008 if i will be the one who will for this i will use seriallize so it will be easier for me to delete add images name on my single field! and the identifier of those images will be the user id or usernames if your not comfortable with serialization maybe you can use the implode and explode! Quote Link to comment https://forums.phpfreaks.com/topic/90453-duplicate-image-name-in-a-database/#findComment-463750 Share on other sites More sharing options...
Northern Flame Posted February 11, 2008 Share Posted February 11, 2008 for the messages you would need a separate table, try creating a table with these fields: to from subject message read to would be the nickname of the user that the message is to and from would me the nickname of the from user subject and message are self explanatory and read you dont need but if you want you can add a feature that tells the user if he has read the message or not. Quote Link to comment https://forums.phpfreaks.com/topic/90453-duplicate-image-name-in-a-database/#findComment-463816 Share on other sites More sharing options...
joanna2008 Posted February 11, 2008 Author Share Posted February 11, 2008 Thank you for your responses and help. Quote Link to comment https://forums.phpfreaks.com/topic/90453-duplicate-image-name-in-a-database/#findComment-463884 Share on other sites More sharing options...
aschk Posted February 11, 2008 Share Posted February 11, 2008 Just going to add my 2 pence (being english) to this topic. I would recommend creating a directory for each user. e.g. <pre> images |-> fred |-> 47b0305771218.jpg |-> 47b0305ecfcc6.jpg |-> joe |-> 47b0306630889.jpg </pre> This helps to keep the logic separation of what you're doing. Also DON'T allow users to name their own files. YOU should be naming them for them. If they want to call the file something inparticular then I recommend storing this as a field (e.g. called title) in your database. PHP provides a nice function called uniqid() which will generate a unique id each time which you can use for the image name. As an added feature you might like to let your users "group" their files into categories. This will probably be a database fields as opposed to another directory leaf. Quote Link to comment https://forums.phpfreaks.com/topic/90453-duplicate-image-name-in-a-database/#findComment-463890 Share on other sites More sharing options...
joanna2008 Posted February 12, 2008 Author Share Posted February 12, 2008 Thanks for the advice! in the message table - would i need to insert a timestamp field - so users can sort messages by time received? (is there an alternate way to do this? is this the best option?) Quote Link to comment https://forums.phpfreaks.com/topic/90453-duplicate-image-name-in-a-database/#findComment-464507 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.