4

リンクをクリックすると、/downloads/download/randomhash が開きます。

randomhash がデータベースにある場合、ダウンロード カウンターをインクリメントしてから、実際のファイル (/uploads/2012/file.png など) にリダイレクトします。

私がやりたいことを行うリダイレクトを除いて、すべてが機能します。なぜ機能しないのかわかりません...

  header("Location: " . $row->uri);
  header("Content-Disposition: attachment; filename=$row->name");

ファイルの最初のロードでは、適切な content-disposition ヘッダー (firebug 内) がありますが、ファイルをダウンロードするように求められません (そうすべきですよね??)。何か案は?

応答ヘッダー:

Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0, public
Connection: Keep-Alive
Content-Disposition: attachment; filename=promotion_photo_2.jpg
Content-Encoding: gzip
Content-Length: 20
Content-Type: text/html; charset=utf-8
Date: Mon, 27 Feb 2012 01:01:22 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive: timeout=5, max=100
Location: /uploads/2012/mediakitD3CF.jpg
Pragma: no-cache
Server: *
Vary: Accept-Encoding
X-Powered-By: *
X-UA-Compatible: IE=Edge,chrome=1
4

1 に答える 1

4

同じ応答で Content-Disposition ヘッダーを設定して、ブラウザーにリダイレクト先を伝えます。私の提案は、リダイレクトなしで、応答で添付ファイルをストリーミングすることです

header('Content-Disposition: attachment; filename=file-to-be-downloaded.jpg');
header('Content-type: image/jpeg'); // or what is relevant, ie application/octet-stream
$fn=fopen("path-to-file/file-to-be-downloaded.jpg","r");
fpassthru($fn);
于 2012-02-27T01:12:30.210 に答える