Page 1 of 1

User Profile Avatar

Posted: Fri Jun 10, 2011 8:29 am
by kalipsso
I was wondering if you can make a tutorial on how to add a user profile picture/avatar...or a gallery for users from which they can pick the profile avatar/picture...that will be interesting...
thank you and regards.

Re: User Profile Avatar

Posted: Fri Jun 10, 2011 12:56 pm
by bowersbros
Its fairly simple.

You probably know how to upload an image (im sure jacek has covered this) And im sure you know how to insert data into a database, and how to fetch data and how to echo out data.

You have everything you need there.

When you upload the image, make sure you upload it to a certain location where they are all stored, and make sure the file name is unique (good technique for this is often just the timestamp, however for popular websites, adding a salt and md5ing it will make it completely unique.

This data you then store into the database alongside the user profile data (in the same row as the person it corresponds to. For the image you store the location on the server from root. Eg. /profile/images/image0123133131.jpg

When you fetch that data on the persons profile page (eg, by using $_GET on the ID field and then fetching all the data you need from the row matching that ID. you get the location of the image, which you then echo out into a <img src="" /> tag.

There you have it.

User Profile Avatars

Re: User Profile Avatar

Posted: Fri Jun 10, 2011 3:23 pm
by kalipsso
bowersbros wrote:Its fairly simple.

You probably know how to upload an image (im sure jacek has covered this) And im sure you know how to insert data into a database, and how to fetch data and how to echo out data.

You have everything you need there.

When you upload the image, make sure you upload it to a certain location where they are all stored, and make sure the file name is unique (good technique for this is often just the timestamp, however for popular websites, adding a salt and md5ing it will make it completely unique.

This data you then store into the database alongside the user profile data (in the same row as the person it corresponds to. For the image you store the location on the server from root. Eg. /profile/images/image0123133131.jpg

When you fetch that data on the persons profile page (eg, by using $_GET on the ID field and then fetching all the data you need from the row matching that ID. you get the location of the image, which you then echo out into a <img src="" /> tag.

There you have it.

User Profile Avatars

Yes...but i was thinking on a user gallery, and the option for the user to select from that gallery the profile picture.( Select picture as profile pic)...that's not the same as uploading a user profile image...and not everyone knows how to do it, that's why it will be a good and useful tutorial..
Regards.

Re: User Profile Avatar

Posted: Fri Jun 10, 2011 3:30 pm
by jacek
bowersbros wrote:adding a salt and md5ing it will make it completely unique.

That wont actually add any more uniqueness. What you are doing to the timestamp is always the same, so the resulting value is still only dependant on the input.

Also, I will add this to the list ;)

Re: User Profile Avatar

Posted: Fri Jun 10, 2011 10:03 pm
by bowersbros
jacek wrote:
bowersbros wrote:adding a salt and md5ing it will make it completely unique.

That wont actually add any more uniqueness. What you are doing to the timestamp is always the same, so the resulting value is still only dependant on the input.

Also, I will add this to the list ;)


Where i said salt, i meant random string ;D