I need to download the file in PHP, but so that the user does not know where the final file is located.

File paid. The user buys it and gets a unique link to download it.

A few questions.

  1. Where the files are usually stored on the server in order not to get them “accidentally”, so to speak.
  2. What will the link look like (what is there to code)
  3. Actually how to download the file to the user (if possible, sample PHP code)
  4. Is there a simple script to learn with this functionality? Well, or some PHP class?
  5. For myself ... What to write to Google, from what to dance?

I myself am just not familiar with the principle of the work of such a thing. I do not know where to start and how to do it.

Thank you in advance!

    1 answer 1

    1) put .htaccess in the folder (any where the files will be) with the entry: Deny all
    2) give all the files through a php script
    3) write some unique hash for the download to the database (for example, md5 (time (). [Id-file]))
    4) after you have given a file by hash - delete this hash from the database or make it [already downloaded]

    • And how to force a file to be downloaded by a script? - inferusvv
    • Into the hash account - it will be available only for one user. No one else on it can download the file, except for the authorized buyer - inferusvv
    • And yes. What is the difference between Deny all and Deny From all? - inferusvv
    • [ readfile($filename) ] [1] [1]: php.net/manual/ru/function.readfile.php - mantigatos pm
    • 1) header('Content-type: application/txt'); // Type header('Content-Disposition: attachment; filename="ИМЯ.txt"'); // name echo $file; // file 2) Deny From all - correctly 3) If you generate a hash random enough and only give out an authorized user (you can write a user – hash to the database) - then the hash will be available only to this user - Maksym Prus