ファイルのアップロードがあるプロジェクトに取り組んでいます。これらのファイルにはランダムな名前が付けられ、Web ディレクトリの外に配置されます。
次に、URL で渡されたパラメーターに基づいてこの画像を取得するスクリプトを用意しましたが、これはまったく問題なく機能します。
ただし、ブラウザーに渡したいヘッダーの配列を作成し、これらをforeach
ループしてループしましたが、何も設定されていないようです。しかし、機能を使用して手動で設定すると、header
機能します! 奇妙な!
さて、header
ループする代わりに関数を使用してもかまいませんが、これが機能しない特定の理由はありますか?
また、上記の方法を使用して、すべてのヘッダーを配列に格納し、コンテンツをブラウザーに配信するときにそれらを処理しますが、前述の問題を見て、それらが実際に渡されているかどうかはわかりません!
私のコードのスニペット:
// Expiry date in seconds, in this instance a year
$expiry_date= ( 60 * 60 * 24 * 365 );
// Our headers
$img_headers= array(
'Content-Type : ' . $mime,
'Cache-Control: no-cache, must-revalidate',
//'Cache-control: max-age=' . $expiry_date,
'Expires:' . gmdate( DATE_RFC1123, time() + $expiry_date ),
'Pragma: ',
'Last-Modified: ' . gmdate( gmdate( DATE_RFC1123 ), filemtime( $image_path ) ),
'Content-Length: ' . ( string ) filesize( $image_path ),
'Content-Disposition: inline; filename="' . $image_name . '"'
);
/*header( 'Content-Type: ' . $mime, TRUE );
header( 'Cache-Control: no-cache, must-revalidate', TRUE );
header( 'Expires: ' . gmdate( DATE_RFC1123, time() + $expiry_date ) );
header( 'Pragma: ', TRUE );
header( 'Last-Modified: ' . gmdate( gmdate( DATE_RFC1123 ), filemtime( $image_path ) ), TRUE );
header( 'Content-Length: ' . ( string ) filesize( $image_path ), TRUE );*/
// Loop through and set up our headers!
foreach( $img_headers as $new_header )
{
header( $new_header, TRUE );
}
// Read our image and end the rest of the file execution
return die( readfile( $image_path ) );
場違いに見えるものはありますか?
前もって感謝します!