I am trying to provide .pdf and .doc files to authorized users on a website. The user can only see the file selection page when logged in but this doesn’t prevent an unauthorized user from viewing the documents if they have knowledge of the full URL.
How can I prevent unauthorized users from accessing these files?
the answer is quite simple,
@Jonnix has posted this as I was typing but I will explain a little more for you
one put your files outside of your public HTML directory if your unable to do this look at @Andri answer for an alternative
E.G cpanel setup
@dhh has posted a basic
download.phpphp file however as your wanting to force download their things you can do like finding and supplying the correct mime type here is an extension on to his code as to the best way to 1 force download of a file, and 2 allow different file typesdownload.php
P.S here is a big list of mime types if you want to add support for other files
https://www.freeformatter.com/mime-types-list.html