how to hide the actual download folder location

前端 未结 3 1537
没有蜡笔的小新
没有蜡笔的小新 2020-11-29 02:33

I want to hide the download folder location so that when the user downloads a file he cannot see the location. I think this can be done using an .htaccess file but how do I

3条回答
  •  孤独总比滥情好
    2020-11-29 03:00

    What you are going to want to do is have the user directed to fake_url.php and then rewrite that URL to a different file - real_url.php. This effectively renders the real_url.php as hidden because the user is unaware of the redirect happening in your .htaccess file.

    RewriteRule fake_url.php(.*)$ real_url.php?$1 [L,QSA]
    

    In your real_url.php, you can read the parameters passed through the redirect and then use something similar to readFile() to send the appropriate file back to the user from within real_url.php

    So the user will only see the URL -
    https://my-secret-site/download.php?file=file_to_download

    And in your real_url.php you'll know what file was requested by inspecting the $_GET['file'] parameter.

    The actual location of the files that the user is downloading does not matter anymore. All downloads go though fake_url.php and only that script needs to know the real location of the downloads folder.

提交回复
热议问题