使用PHP自动查找文件目录路径

I upload file in my server and I have this url from my databse:

                  |---> subdomain for xammp in localhost windows
                  |
http://localhost/cms/uploads/files/1/final.mp4

Now for download i need to show file directory path of file like:

../cms/uploads/files/1/final.mp4 // This worked for subdomain
OR
./uploads/files/1/final.mp4 // This worked for domain root

how do auto find server path directory for file ?!

You can check if in your URL you have "/cms/"

if (!strstr($_SERVER['REQUEST_URI'],'/cms/')){
  $pathdir = '../cms/';
} else {
  $pathdir = './';
}