Jump to content

Duplicate image name in a database


joanna2008

Recommended Posts

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. :-\

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.