Database design for sharing photos site? - php

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?

1 - At a minimum your database should consist of
users: user_id, user_name, pw_hash, salt
photos: photo_id, user_id, photo_path
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.

Related

Store images or folder path in database: how?

My plan is to write a few news articles each day to display on my website.
Each news article will contain a certain amount of pictures. There can be up to 50 images in an article.
At this moment my images get stored like this:
/images/2014/theme1/01.jpg
/images/2014/theme1/02.jpg
/images/2014/theme2/01.jpg
/images/2014/theme2/02.jpg
...
/images/2014/theme2/50.jpg
I'd like to know how I can store these images into my database. I already read a lot about this subject and heard that storing the folder path into the database is better than the images itself.
But how should I do this? The maximum amount of pictures per article is 50, so do I really have to create 50 columns (one for each possible image) or is there another way to do is?
#Luca Prodan Flow this Link. .Net core Add folder in static folder (www) and save image file and store the: "PathWithFolderName + "/ImageName.png" in database.

How to set directory for images in my website?

My aim is to make a multi-user website which may have between 30 to 3000 users. once one uploads an avatar or an image, How should it handle directory naming?
1- all files in one folder?
2- all files in folders separated by day?
/img/upload/2013/05/14/brothers32_5464562.jpg
3- all files in folders separated by user name?
/img/upload/users/brothers32/5464562.jpg
I don't like change my way in mid-way.so, according to your experience which way do you suggest to choose?
I agreed with StarCub until I read each user could upload multiple images. Then I'd do this:
Profile picture. All in 1 folder (as StarCub suggested):
/img/upload/users/USERID.jpg
Uploaded pictures. All in another folder:
/img/upload/userimg/2013/PICID.jpg
EXCEPT if you expect users to upload many pictures. I'd say 1000-5000 pictures per folder is good, so maybe order them by month depending on what kind of site the page is.
If you only have to up 3000 users and each user only has one avatar, I would just put them all in one folder (OPTION 1) and name them use user ID or some sort of unique identifier for that user.
If each user can upload multiple images, then I would use OPTION 3.

Adding facebook profile picture to high scores table using PHP

I was able to make a small flash game after receiving a lot of help here at Stackoverflow, I was able to post the score variable to a php file and then to database , now I would like to make a small high score list and I know I would need to use the FB users and scores previously saved to the database’s table, my question is how could I add the profile picture thumbnail besides each user’s score ? Should I save another parameter to the database or should I use the following line when I print the databse info in the html file ?
<img src="https://graph.facebook.com/<USER_ID>/picture"/>
I’m really sorry if this is a silly question, I’m really inexperienced with facebook stuff. Thanks!
This is indeed the best way to display profile photos of your users (or any users). There is no need to store URL's or even download the images to your server. All you need is the users Facebook ID.
If the pictures are those of the users friends, the chances are that they already have those images cached in their browser so it's a good idea to take advantage of that.
You can also add some parameters to that call to get other sizes of the profile picture -
https://graph.facebook.com/UID/picture?type=large
The values that are accepted are -
small
normal
large
square

Codeigniter/PHP: Image db storage?

If I want each user in my web app to be able to upload about 6 pictures with a description, what is the best way to store that info in the db?
How would you do it?
i would save the image files to a location in the file system.
then, keep a database table for images that contains id, filepath, description.
you may also want to keep other info in the image table as well, for instance, which user the image belongs to, and which is the main image, width, height, etc.

Storing pictures per user on website (php)

Users of the website need to able to store images in their "area" , should I store these in the database directly or create a directory for each user.
Or should I just have a single directory for all images and in the database store a list of images that each user owns?
I'm looking for the most effecient way, which I think is a folder for each user?
If you have many pictures per user like avatar and gallery of photo created by the user then use separate folders named with the user id or a hash of the user id.
If you only store avatars have one big folder where the name of the image is the user id or hash of the user id.
It depends on how many pictures there are.
If there is only one picture per user, then perhaps all in the same directory.
However if you have albums and such, there can be millions of photos with all the users photos in the same folder. This would be very slow to search in. Then I'd go with one folder per user.
Also, never give direct access to the folders. Use your database to link to the files.
Better use folder or a cache folder. You can also use resizing functions for the image, so if user upload a large scale picture. Your script will manage to create different sizes, like avatar pics. And cache those images. So thumbnail or avatar viewers only viewing the cache image of the original image. And the large image is usable for future work, like a bigger preview of the avatar.

Categories