4

これは昨夜は機能していましたが、現在は機能していないため、誤って何かを変更したに違いありません。

私がやろうとしていることは、これらのヘッダーから明らかです。

Content-Disposition: attachment;filename=english_customizable.xml
Location: http://tortoisewrath.com/files/2.xml

ただし、このヘッダーが送信されるとContent-Disposition、リダイレクト後にその部分が機能しません。

...どうして?

4

1 に答える 1

2

あなたがやろうとしていることは、この質問をチェックすることはお勧めできません。ヘッダーの場所 + コンテンツの配置

Content-Disposition + Location ヘッダー

しかし、それを行うことはできます。それを機能させるには、送信する前に応答全体をバッファリングする必要があります。これは、出力バッファリングで行うことができます

Locationそうしないと、ファイルがダウンロードされる前にブラウザがヘッダーを解釈する可能性があります。どちらにしても大雑把なので、これを行うべきではありません。

「名前を付けて保存」を強制Content-Disposition: attachment;すると、クライアントがどこにも移動/移動しないようになるため、以下の方法だけで問題ないことに注意してください。

PHPでファイルをストリーミングする

適切な場所に頭脳を持っている人の言葉を引用すると:

// To use header() with 'content-type', why don't you use mime_content_type() function rather than checking the type on the basis of extension? 
// Example code: 

<?php 
$file="test.docx"; 
header("Pragma: public"); 
header('Content-disposition: attachment; filename='.$file); 
header("Content-type: ".mime_content_type($file)); 
header('Content-Encoding: identity'); 
ob_clean(); 
flush(); 
readfile($file); 
?> 

// Use $file to map to whichever type of file. 
// Note: the mime types should already be defined in apache settings

ソース: http://www.php.net/manual/en/function.header.php#107581

Content-Transfer-EncodingHTTP には実際には存在しない元の回答が使用されていることに注意してください。そのソースの下のコメントはそれを説明しています: http://www.php.net/manual/en/function.header.php#107044

于 2012-06-22T20:12:15.383 に答える