通过 readfile() 更改文件的 CRC
我设置了这段代码,让用户可以通过我的服务器从他们指定的 URL 下载文件。文件使用 readfile() 进行流式传输,因此它只使用我的带宽。
<?php
set_time_limit(0);
$urlParts = explode("/", $_SERVER['PHP_SELF']);
$file = $urlParts[3];
header("Cache-Control: public, must-revalidate");
header("Pragma: hack");
header("Content-Type: application/force-download");
header('Content-Disposition: attachment; filename=' . $file);
header("Content-Transfer-Encoding: binary\n");
readfile($file);
?>
该脚本可以工作,但不会更改下载文件的 CRC 哈希值。我想要它做的是将一些随机位附加到文件末尾,这样它就可以更改哈希值而不破坏它。我尝试在脚本末尾添加类似 echo md5(rand() .time());
的内容,但它不起作用。
如果这对于像 cURL 这样的东西是可能的,如果有人可以提供一些代码示例,我将不胜感激,因为如果可能的话我会切换到 cURL。
感谢您的帮助。
I have this code set up that lets a user download a file through my server from a URL they specify. The file streams through using readfile() so it only uses my bandwidth.
<?php
set_time_limit(0);
$urlParts = explode("/", $_SERVER['PHP_SELF']);
$file = $urlParts[3];
header("Cache-Control: public, must-revalidate");
header("Pragma: hack");
header("Content-Type: application/force-download");
header('Content-Disposition: attachment; filename=' . $file);
header("Content-Transfer-Encoding: binary\n");
readfile($file);
?>
This script works, but it does not change the CRC hash of the downloaded file. What I want it to do is append some random bits to the end of the file so it can change the hash without corrupting it. I have tried adding something like echo md5(rand() . time());
to the end of the script but it doesn't work.
If this is possible with something like cURL I'd appreciate if someone could put up some code samples, because i'd switch to cURL if this was possible.
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,你的代码对我有用:
test.php:
toread.txt:
现在使用curl,我得到以下结果:
第二个:
Hmm, your code works for me:
test.php:
toread.txt:
Now using curl, I get the following results:
And the second one: