Reputation: 309
I still really don't understand image storing and showing.
Let me give you an example, what I did first (people say my logic is a bad idea).
I did at first, every user has a folder with an user_id
, and after the form was submitted it saves the image with an unique name
in to this folder and the image name too, with the extension in the database, and I've shown the image matching the file name in the folder with the saved name in the database,
Example (here let's skip the unique name just to make it more clear a bit)
an user uploads an image named butterfly.jpg
the image is stored in the database
id | name |
1 | butterfly.jpg |
and stored in a folder too with the same name
/images/user_id/butterfly.jpg
and showing the image this way
<img src="images/unser_id/<?php echo $name ?>" alt="">
So it matches the names (I hope I was clear sorry if not)
So I know my logic is a bad logic, because storing the names in the database will lead to a huge one, maybe to other problems in the later future
And what I would like to ask if its not a big request, if someone could write down a logical thread with some example codes (I'm not asking to write it for me), just to give me the idea what I'm missing
And other questions about what I read about
Some developers say, they only store the image folder name in the database, that is okay, but how I am able to show those images if only the folder name is stored? because it will maybe have more than one image like 3 one the original image and 2 other thumbnails.
So please don't hate me with this question, I only asked this because I would like to learn and get advice from a more experienced developer.
Upvotes: 0
Views: 113
Reputation: 1166
I think you're on the right path. The correct way of doing it is - to upload the file to your server and then put the image path into your database, as far as i can tell, you're doing it right. :-)
Upvotes: 1