Save full path in the bank or just name with extension?

Asked

Viewed 1,280 times

4

In the systems I used to develop back in the day, I used to save the entire file path in the database .

Example:

c:\xampp\htdocs\teste\imagens\post_44\stack_overflow.png

// Image table

imagem 
 - id = 1
 - imagem = imagens/post_44/stack_overflow.png
 -post_id = 44

Then, when I started using frameworks, I started to put only the name of the file with the extension in the record (and the other data picked according to the query in the database).

image
  - id = 1
  - image = stack_overflow.png
  - post_id = 44

In this case, I do this because I develop with the Framework in PHP, and it makes it easier for me to "mount" the path of this image.

But, when it comes to other cases, as in systems made "at hand", which of these is the best way to store a file name in the database (also taking into account performance and maintenance)?

  • 1

    I am against saving the path, ever wondered if for some reason you need to rename the folder of the files in the application?

  • They scored to close. It may even be a bit opinionated, but it’s a problem that many beginners can go through.

  • I see no reason to close this question. It is perfectly possible to list the positive and negative points of each option. It is not just a matter of opinion.

1 answer

8


In my opinion what would make it easier for maintenance would be to store only the name.extension.;

  • Let’s look at a little case:

    You decide to abruptly modify the current system, changing several things, including the destination of the files, in the end... it would be much easier to change the path of the files only in one place is not?

    Imagine you change record by record in the database for the new paths, it would be an unnecessary job; remembering that this is a personal opinion.

  • As a matter of performance, I don’t think it would change much store the entire path vs file name only (can’t confirm or confirm this information).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.