开发者

PHP User Avatars [duplicate]

开发者 https://www.devze.com 2023-04-02 01:13 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Storing Images in DB - Yea or Nay?
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Storing Images in DB - Yea or Nay?

I am building a system in which the users can upload their own avatars. I found that there are 2 ways of doing that - storing the image into the database or s开发者_如何学Ctoring actual path to the image in the database and saving the image on the hard drive. I am wondering which of these ways to use. So which of them is better and which of them should I choose?


The normal way to do this is the 2nd one, it's too much strain on the DB to be storing the complete image as a BLOB, simply store the image on your webroot and the path in your DB table


Both ways works fine. It's more a matter of organization in my opinion. For example, you can backup you images within your data at once if it is on your database, but is really strain -like they said - but it's a advantage.


I wouldn't store the images in a database, as 8vius points out, it's too much strain on the database. Instead of storing the path in the database, you could also retrieve the images by some logical algorithm. For example, if your users have a unique identifier you can contruct the path to the image with that. So if your user has id 1080, the path would be something like /avatars/1080.png

By the way, are you familiar with gravatar.com? If it suits your needs, it will save you the trouble of building the feature yourself.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号