How can i accept profile pictures from users and display it with their profile???
Saving images in database(profile pics)
Page 1 of 113 Replies - 1960 Views - Last Post: 10 November 2008 - 08:57 PM
Replies To: Saving images in database(profile pics)
#2
Re: Saving images in database(profile pics)
Posted 10 November 2008 - 03:46 AM
Don't.
Save the images in a file, and save the file reference in the database.
Save the images in a file, and save the file reference in the database.
#3
Re: Saving images in database(profile pics)
Posted 10 November 2008 - 12:29 PM
Just to clarify, what Hary is talking about is saving the file name in the database and then pulling that whenever you need to display the image.
You would have a field called "profileImage" or something to that sort. When a user uploads their picture you get the file name and check to make sure a file with that name doesn't exist. Do any other error checking, and then when you input the user's information into the data, you would insert the file name into profile image. The file gets moved to a directory that holds all the user images. When you generate the user's profile, simply pull the file name and build do something like this:
You don't want to store files in your database, just file name references.
You would have a field called "profileImage" or something to that sort. When a user uploads their picture you get the file name and check to make sure a file with that name doesn't exist. Do any other error checking, and then when you input the user's information into the data, you would insert the file name into profile image. The file gets moved to a directory that holds all the user images. When you generate the user's profile, simply pull the file name and build do something like this:
<img src="path_to_profile_images/<?= $row['profileImage']; ?>">
You don't want to store files in your database, just file name references.
#4
Re: Saving images in database(profile pics)
Posted 10 November 2008 - 04:12 PM
akozlik, on 10 Nov, 2008 - 11:29 AM, said:
When a user uploads their picture you get the file name and check to make sure a file with that name doesn't exist.
The post above is good, but the only recommendation I'd make over it is to have the file name randomize into, say, a random 9 digit number, keeping the original file's file extension. Then, there's less of a chance of file naming issues
Of course, you'd still want the code there to check for duplicates.
#5
Re: Saving images in database(profile pics)
Posted 10 November 2008 - 04:14 PM
Valek, on 10 Nov, 2008 - 06:12 PM, said:
the only recommendation I'd make over it is to have the file name randomize into, say, a random 9 digit number, keeping the original file's file extension. Then, there's less of a chance of file naming issues 
If you really want to make sure you get a random file name that won't be uplicated you could always hash the timestamp and use that as the filename.
#6
Re: Saving images in database(profile pics)
Posted 10 November 2008 - 04:15 PM
That's an even better idea
#7
Re: Saving images in database(profile pics)
Posted 10 November 2008 - 04:46 PM
hashing the timestamp takes into account the date as well correct?
Just time could give a duplicate but I'm pretty sure timestamps have date and time correct?
Just time could give a duplicate but I'm pretty sure timestamps have date and time correct?
#8
Re: Saving images in database(profile pics)
Posted 10 November 2008 - 04:49 PM
Right, the timestamp should give you a large integer which is the amount of time that has elapsed since the unix epoch. Since this number is always different, and since hashing will never (hopefully) create a duplicate hash from two separate sources, that should be a safe way to encode your image names.
#9
Re: Saving images in database(profile pics)
Posted 10 November 2008 - 05:07 PM
Exactly. THe only way to duplicate it would be to have two people upload an image at precisely the same second, but one way around that one would be to have it hash the same timestamp with a different hash type. For instance, if you're using MD5 and that filename is already there, have it hash in SHA1. Then you still have a unique filename for it without overlap
#10
Re: Saving images in database(profile pics)
Posted 10 November 2008 - 05:09 PM
I believe it is impossible to have two identical timestamp values, as even if someone uploaded at 12:01:57 the milliseconds would be different, resulting in a different timestamp
#12
Re: Saving images in database(profile pics)
Posted 10 November 2008 - 05:19 PM
Well I stand corrected, never seen a Time functions that didn't count milliseconds before. Thanks
#13
Re: Saving images in database(profile pics)
Posted 10 November 2008 - 05:20 PM
It caught me off guard when I started using PHP. I figured it out when I was testing differences for a caching function and noticed an hour was 3600
This post has been edited by Valek: 10 November 2008 - 05:20 PM
#14
Re: Saving images in database(profile pics)
Posted 10 November 2008 - 08:57 PM
Well you could use microtime() assuming you meet the criteria
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote







|