Is there a good implementation of partial file downloading in PHP?

前端 未结 5 566
情深已故
情深已故 2020-12-08 22:39

I\'m writing a PHP script that allows the user to download a file. Basically the idea is to prevent the file being downloaded more than X times, since it is paid content, an

5条回答
  •  囚心锁ツ
    2020-12-08 23:20

    See http://us3.php.net/manual/en/function.fread.php

    An alternative is to let the web server can handle http by redirecting to the file in question.

    A PHP script can do any checks needed (security, authentication, validate the file, incrementing the download count) and any other tasks before calling header("Location $urltofile");

    I tested this with apache. Interrupt/resume download works. The server's mime type configuration will determine client behavior. For apache, if defaults in mime.types are not suitable, configuration directives for mod_mime could go in a .htaccess file in the directory of the file to download. If really necessary, these could even by written by the PHP script before it redirects.

提交回复
热议问题