共享照片网站的数据库设计?
我正在使用 php 和 mysql。如果我想做一个共享照片网站,上传和显示照片的最佳数据库设计是什么。这就是我的想法:
domain:
|_> photos
|_> user
登录的用户将上传照片 [http://www.domain.com/user/upload.php]
照片存储在文件系统中,照片路径存储在数据库中。所以,在我的照片文件夹中将是这样的:照片/用户A/子文件夹+照片,照片/用户B/子文件夹+照片,照片/用户C/子文件夹+照片等
公共/其他人可以在以下位置查看他的照片: [http://www.domain.com/photos/user/?photoid= 123]
其中 123 是 photoid,从那里,我将从数据库查询以获取路径并显示图像。
我的问题:
照片共享网站(如 flickr)的最佳数据库设计是什么?
如果我继续在“照片”文件夹中创建新文件夹,会出现任何问题吗?如果有数十万用户注册怎么办?最佳实践是什么
我应该保留什么尺寸的照片?目前我只存储缩略图 (100x100) 和(最大)1600x1200 像素照片。
开发照片分享网站时我还应该注意哪些事项?
I am using php and mysql. If I want to do a sharing photos website, whats the best database design for upload and display photos. This is what I have in mind:
domain:
|_> photos
|_> user
Logged in user will upload photo in
[http://www.domain.com/user/upload.php]
The photos are stored in filesystems, and the path-to-photos stored in database. So, in my photos folder would be like: photos/userA/subfolders+photos, photos/userB/subfolders+photos, photos/userC/subfolders+photos etc
Public/others people may view his photo in:
[http://www.domain.com/photos/user/?photoid=123]
where 123 is the photoid, from there, I will query from database to fetch the path and display the image.
My questions:
Whats the best database design for photo-sharing website (like flickr)?
Will there be any problems if I keep creating new folder in "photos" folder. What if hundreds of thousands users registered? Whats the best practices
What size of photos should I keep? Currently I only stored thumbnail (100x100) and (max) 1600x1200 px photos.
What others things I should take note when developing photos-sharing website?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1 - 您的数据库至少应包含
为您想要的额外功能添加的字段(标签、last_seen、photo_upload_date、photo_views 等...)
2 - 不要过早优化。我会为每个用户添加一个用户/用户名文件夹,并将用户照片转储到其中。
3 - 我建议保留原始尺寸、缩略图和适合您网站的尺寸。因此,如果您的布局包含最大宽度为 850 像素的照片,请将所有照片的大小调整为最大宽度 850 像素。如果您的布局发生变化,您可以使用原始图片并将其调整为新尺寸。
4 - 关于图像上传安全性,某处有一个很好的答案,但我找不到它。生病继续寻找。
考虑使用 CDN: https://stackoverflow.com/questions/72369/whats-the-best-cdn-for-image-hosting-on-a-high-volume-web-site
关于可扩展性的精彩演讲,关于缩略图的部分您最好观看:http://www.youtube.com/watch?v= ZW5_eEKEC28。该视频讨论了您可能感兴趣的 ext3 文件系统中每个目录的文件限制。
1 - At a minimum your database should consist of
fields would be added for extra functionality you wanted (tags, last_seen, photo_upload_date, photo_views, etc...)
2 - Dont prematurely optimize. i would go with adding a users/username folder for each user and dumping the users photos in there.
3 - i recommend keeping the original size, thumbnail, and a size that is suited for your site. so if your layout holds a photo with max width of 850px resize all photos to a max 850px wide. If youre layout changes you can use the original picture and resize them to the new size.
4 - there is an excellent answer on SO somewhere about image upload security but i cant find it. ill keep looking.
think about using a CDN: https://stackoverflow.com/questions/72369/whats-the-best-cdn-for-image-hosting-on-a-high-volume-web-site
good talk on scalabilty, the section on thumbnails would be good for you to watch: http://www.youtube.com/watch?v=ZW5_eEKEC28. this video talks about a file-per-directory limit in ext3 filesystems you may be interested in.