I am trying to make a simple website where a logged-in user can upload images in his profile and can retrieve these images and show it on the webpage of his profile. My first question is, what are the attributes of table of images which is owned by the logged-in user in the database? Second question is, is it a nice approach to only save the image file path in the table instead of storing the whole image? TIA
Asked
Active
Viewed 72 times
0
-
You'll soon hear several opinions stating that you should never ever store files in a database, for absolutely no reason. Reality is never so simple and both methods can make sense if you know what you're doing. Using the DB provides DB goodies like integrity, transactions, cascaded deletions, coherent backups... However, for this precise DBMS and use case, you're probably better off using the file system. – Álvaro González Apr 12 '17 at 09:02
2 Answers
0
Yes you are right with saving the image location in the database.
Use PHP to move the tmp image to your images directory on your server and then save whatever data you want to associate with the image along with it eg:
+----+------------------------------------+------------+---------+
| id | image_location | image_name | user_id |
+----+------------------------------------+------------+---------+
| 1 | /images/myprofile.jpg | Jason | 12345 |
+----+------------------------------------+------------+---------+
Note the user id could be who it belongs to (owner). then just make sure when the user logs in their user_id
is stored in the session that you can refer back to it when querying the table for their images.

Jason Joslin
- 1,154
- 8
- 23