我正在處理上傳文件的項目。這些文件被賦予了一個隨機的名字,並放在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));
任何那裏,看起來格格不入?
在此先感謝!
廢話,我有點評論自己的頭! 不能相信我錯過了這樣一個簡單的錯誤! *感嘆*非常感謝!我現在覺得很蠢!嘿 – Azirius 2012-04-15 01:37:54