It is common practice to upload files beyond the root of the document and, as a rule, use randomized file names, which are then mapped to the correct item / object / message in the database. If additional permissions are required to access the files, make sure that you check them before downloading is allowed, and, of course, you will only download authenticated users.
Fileinfo finfo_ mimety, , , -, ".txt", , , ".jpg" jpeg based . , MSMMype-, , -msword. , , (xls, ppt, doc ..).
PHP , -, . mime , .
header("Content-type: application-whatever");
header("Content-length: size-of-the-file-in-bytes");