[請益] header()
我是用Discuz!做的
因為網站能使用的記憶體只有8MB
當傳送超過8MB的檔案時會出現問題(下載的檔案為0位元組)
我試著修改attachment.php
header('Cache-control: max-age=31536000');
header('Expires: '.gmdate('D, d M Y H:i:s', $timestamp + 31536000).' GMT');
header('Content-Encoding: none');
//header('Content-Length: '.$filesize);
//forbid flash be opened directly
//header('Content-Disposition: '.(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')
? 'inline; ' : 'attachment; ').'filename='.$attach['filename']);
header('Content-Disposition: attachment; filename='.$attach['filename']);
header('Content-Type: '.$attach['filetype']);
@$fp = fopen($filename, 'rb');
@flock($fp, 2);
$attachment = @fread($fp, $filesize);
@fclose($fp);
echo $attachment;
就將,後來我試著用Location的方式,改成下面的樣子
if ( $filesize > 8388608 ){
header('Location: attachments/'.$attach['attachment']);
}else{
header('Cache-control: max-age=31536000');
header('Expires: '.gmdate('D, d M Y H:i:s', $timestamp + 31536000).' GMT');
header('Content-Encoding: none');
//header('Content-Length: '.$filesize);
//forbid flash be opened directly
//header('Content-Disposition: '.(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')
? 'inline; ' : 'attachment; ').'filename='.$attach['filename']);
header('Content-Disposition: attachment; filename='.$attach['filename']);
header('Content-Type: '.$attach['filetype']);
@$fp = fopen($filename, 'rb');
@flock($fp, 2);
$attachment = @fread($fp, $filesize);
@fclose($fp);
echo $attachment;
}
if(!$isimage) {
updatecredits($discuz_uid, $creditspolicy['getattach'], -1);
}
會變成一個充滿亂碼的頁面,我試著在前面在加入表頭
if ( $filesize > 8388608 ){
header('Content-Disposition: attachment; filename='.$attach['filename']);
header('Content-Type: '.$attach['filetype']);
header('Location: attachments/'.$attach['attachment']);
}else{
結果是
無法顯示 XML 網頁
無法使用 樣式表檢視 XML 輸入。請更正錯誤,然後按 重新整理按鈕,或者稍後再試一
次。
--------------------------------------------------------------------------------
文字內容包含無效的字元。處理資源
'http://localhost/Discuz/upload/attachments/forumid_1/ACD%20Systems2_1WONay4mpVBR.rar'
發生錯誤。
但我按右鍵檢視原始碼時,出現的內容是要下載的檔案,而且網址也沒問題
有辦法改好嗎??
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 203.203.192.14