Protected File Download Script. Almost there

后端 未结 4 1363
無奈伤痛
無奈伤痛 2021-02-11 08:55

I have a file that users will purchase via paypal, clickbank and paydotcom. I have to host the file\'s download page on my server.

I\'ve placed the file in a directory o

相关标签:
4条回答
  • 2021-02-11 09:08

    You can use the parent directory shortcut ../ in your $path or the dirname function like:

    $parent_dir = dirname( dirname( __FILE__ ) );
    // first dirname is the directory of this file, second goes up one level, etc.
    

    BTW, beware of indicating the path in your URL, one could read other files (like configuration files or ohter private files) by changing it to download.php?download_file=../../private/bank_certificate.pem. You should use realpath to get the absolute path of the file and compare it to an "authorized for download" file list.

    0 讨论(0)
  • 2021-02-11 09:10

    Custom coding may not be the best solution these days for a file download script. Check out Drupal which has file download modules, that can be integrated with its Clickbank module as well: http://drupal.org/project/clickbank_ipn

    0 讨论(0)
  • 2021-02-11 09:10

    well if public_html is your doc root then you should be able to get the path to download would be

    realpath($_SERVER[DOCUMENT_ROOT].'/../download');

    0 讨论(0)
  • 2021-02-11 09:18

    You just need to consider the path like a normal directory path, not a web one. so to go up a level simply "../" e.g.

    if you structure is like this

    /path2file/inhere.pdf /public_html/download.php

    the path to the file would simply be from download.php "../path2file/inhere.pdf"

    0 讨论(0)
提交回复
热议问题