0

ユーザーが指定した 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 に切り替えるからです。

ご協力いただきありがとうございます。

4

1 に答える 1

0

うーん、あなたのコードは私のために働きます:

test.php:

set_time_limit(0);

$urlParts = explode("/", $_SERVER['PHP_SELF']);
//$file = $urlParts[3];
$file = 'toread.txt';

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);
echo md5(rand() . time());

?>

toread.txt:

toread.txtの中身です

curl を使用すると、次の結果が得られます。

>curl -i http://example.com/test.php
HTTP/1.1 200 OK
Date: Tue, 04 Mar 2014 07:09:39 GMT
Server: Apache
Cache-Control: public, must-revalidate
Pragma: hack
Content-Disposition: attachment; filename=toread.txt
Content-Transfer-Encoding: binary
Transfer-Encoding: chunked
Content-Type: application/force-download
Proxy-Connection: Keep-Alive
Connection: Keep-Alive
Age: 0

This is the content of toread.txt38d8a8009fad7315bdf5e823a06018e7

そして2番目のもの:

>curl -i http://example.com/test.php 
HTTP/1.1 200 OK
Date: Tue, 04 Mar 2014 07:09:57 GMT
Server: Apache
Cache-Control: public, must-revalidate
Pragma: hack
Content-Disposition: attachment; filename=toread.txt
Content-Transfer-Encoding: binary
Transfer-Encoding: chunked
Content-Type: application/force-download
Proxy-Connection: Keep-Alive
Connection: Keep-Alive
Age: 0

This is the content of toread.txt3b87356ea9ee007b70cfd619e31da950
于 2014-03-04T07:12:33.427 に答える