'how to prevent url force access to files

After uploading a file to the server, I store the file path in the database.

http://localhost/ramseyer/apps/uploads/-d10ddbe8164659168192848723610514347.docx

Since the platform I am building has user access levels, I realize that even if the user is not logged in with authorization, a user can still access the file only if they somehow get to know the URL.

I've read many articles about path traversal but did not find answers.

Is there a way to forbid a user who tries to enter the file URL in the address bar just to access the file? Just as you forbid a user from accessing directories with htaccess ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source