PHP中有部分文件下载的好实现吗?
我正在编写一个允许用户下载文件的 PHP 脚本。基本上,这个想法是防止文件被下载超过 X 次,因为它是付费内容,并且链接不应该传播。
由于文件相当大,因此最好实现恢复。我已阅读标准,但它是相当长并且允许一定的灵活性。由于我需要快速完成它,因此我更喜欢此功能的稳定且经过测试的实现。
谁能指出我这样的脚本吗?
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, and the link should not be spread around.
Since the files will be pretty large, it should be good to implement resuming. I've read the standard, but it's pretty long and allows for some flexibility. Since I need to get it done quickly, I'd prefer a stable, tested implementation of this feature.
Can anyone point me to such a a script?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
看来我自己找到了我需要的东西。为了让其他人可以从中受益,以下是链接:http://www.coneural.org/florian/papers/04_byteserving.php
以防万一原始页面停止工作(脚本已经很旧了),这里是它的副本:
Seems that I found what I needed myself. So that other may benefit from this, here is the link: http://www.coneural.org/florian/papers/04_byteserving.php
And just in case the original page stops to work (the script is pretty old already), here is a copy of it:
您应该使用 PEAR HTTP_Download。它非常易于使用,并且允许仅恢复下载文件:
http://pear.php.net/manual/en/package.http.http-download.intro.php
You should be using PEAR HTTP_Download. It is pretty easy to use and it allows download resuming just file:
http://pear.php.net/manual/en/package.http.http-download.intro.php
基于此:
http: //w-shadow.com/blog/2007/08/12/how-to-force-file-download-with-php/
(你也可以使用)
我做了一个小库,它可以PECL http_send_file 扩展的作用:
http://php.net/manual/en /function.http-send-file.php
(您也可以使用)
该库类似于 http_send_file,但如果您没有安装 PECL 库的选项,您可以使用 http-send-文件库:
https://github.com/diversen/http-send-file
Based on this:
http://w-shadow.com/blog/2007/08/12/how-to-force-file-download-with-php/
(which you also could use)
I've made a small lib that does what PECL http_send_file extension does:
http://php.net/manual/en/function.http-send-file.php
(which you also could use)
The lib resembles the http_send_file, but if you don't have the option of installing the PECL lib, you could use the http-send-file lib:
https://github.com/diversen/http-send-file
请参阅 https://www.php.net/manual/en/function.fread .php
另一种方法是让 Web 服务器可以通过重定向到相关文件来处理 http。
PHP 脚本可以在调用 header("Location $urltofile"); 之前执行任何所需的检查(安全性、身份验证、验证文件、增加下载计数)以及任何其他任务。
我用阿帕奇测试了这个。中断/恢复下载工作。服务器的 mime 类型配置将决定客户端的行为。对于 apache,如果 mime.types 中的默认值不合适,则 mod_mime 的配置指令可以放入要下载的文件目录中的 .htaccess 文件中。如果确实有必要,这些甚至可以由 PHP 脚本在重定向之前编写。
See https://www.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.
也许您可以使用 而不是在 Web 服务器中实现 Web 服务器(哟,天啊!) mod在lighttpd中下载前触发或mod X-Sendfile适用于lighttpd和Apache2 ?
Perhaps instead of implementing web server in a web server (yo dawg!) you could use mod trigger before download in lighttpd or mod X-Sendfile available for both lighttpd and Apache2?