D
D
Dmitriy2019-11-03 20:36:48
Database design
Dmitriy, 2019-11-03 20:36:48

What is the best way to write the path to the user's avatar?

What is the best way to write the address of the user's avatar in the database.
1st option:
"avatar.jpg"
2nd option:
" localhost/path/to/images/avatar.jpg "
I think the second one is better, because it's easier to work with the path, but if you suddenly have to, for example, a folder or drag and drop or rename , then everything will break, then the first one is better.
I use smart, but I don’t know how to implement the first one yet.
What are some other thoughts on this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
orbit070, 2019-11-03
@orbit070

Only the path/to/images/avatar.jpg part needs to be kept, and it should never change. Tomorrow, instead of localhost, you will move to a normal server and you will have to change paths everywhere if you make it part of the path too, and after a while the ip or domain and AP will change, in general, such data should never be made part of the path, but that's all what's next - the folder structure to ava and its name - this is necessary, because the folder structure (that is, the path to ava) will be the same on any server and domain

A
Alexey Andreev, 2019-11-22
@LostAlly

Options.
1. Do not store the name of the avatars in the database at all, but name the file according to the user id and store all the avatars in a separate folder. Well, the path to this folder is set in the settings.
2. Store as a file name without extension if all images have the same extension or with extension if there are options.
I don’t see the point of storing the path, well, or in very specific cases.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question