2011-10-13 32 views
0

我有一個字節的數據損壞我的word文檔的問題。當我從服務器上下載時,它會打開,但是當我強制從網上下載時,文件大一個字節並且損壞。我一直在尋找,直到我爲了「額外」的空間而臉色發青。問題與輸出流中的空白損壞文檔

在Windows奇怪的是,如果我點擊恢復文件出來罰款....

public function DownloadDocx() 
{ 
    $this->_extension = "docx"; 
    $args = func_get_args(); 
    $newName = trim($args[0]); 
    ob_flush(); 
    if (!empty($newName)) { 
     $fileName =$_SERVER['DOCUMENT_ROOT'] . '/wills/docs/' .$newName; 
    } else { 
     throw new Exception("Invalid document name"); 
    } 
     if(strstr($_SERVER["HTTP_USER_AGENT"],"MSIE")==false) { 
     header("Content-type: application/vnd.openxmlformats-officedocument.wordprocessingml.document"); 
     header("Content-Disposition: inline; filename=\"". $newName . '.' . $this->_extension."\""); 
     header("Content-Length: ".filesize($fileName . '.' . $this->_extension)); 
    } else { 
     header("Content-type: application/force-download"); 
     header("Content-Disposition: attachment; filename=\"". $newName . '.' . $this->_extension."\""); 
     header("Content-Length: ".filesize($fileName . '.' . $this->_extension)); 
    } 
    header("Expires: Fri, 01 Jan 2010 05:00:00 GMT"); 
    if(strstr($_SERVER["HTTP_USER_AGENT"],"MSIE")==false) { 
     header("Cache-Control: no-cache"); 
     header("Pragma: no-cache"); 
    } 

    readfile($fileName . '.' . $this->_extension); 
} 

回答

0

之後readfile($fileName . '.' . $this->_extension); add exit;

如果問題仍然存在,請嘗試在函數die('.');的開頭添加,如果點(。)是第一個字符,請運行腳本並查看頁面源代碼。

+0

不僅僅是它的一個空間......我可以在源代碼中看到只是無法找到它爲我的生活。 – Blake

+0

這個問題已經解決了,我剛剛開始在死亡的頂部,然後到了最後。 – Blake

0

這類問題通過一個很長的路的最常見原因是<?php之前或之後空白字符?>

請注意,您可能實際上並不需要在純PHP代碼的文件中關閉?>,這有助於避免此問題。

+0

是的,檢查。雖然它是一個偷偷摸摸的小角色。 – Blake

+0

這已解決。我剛剛從死亡的頂端開始,進入底部。感謝您的幫助 – Blake

+0

你有沒有在任何地方調用'include()'/'require()'?記得也要檢查這些文件......基本上,這種可能發生的* only *方式(即輸出1個單個字符)是如果明確地調用'echo'或'print',或者在''標籤。因此,搜索* all *您的腳本用於'echo' /'print'的源代碼文件,並檢查所有*文件中的標籤(搜索include \'require'的出現情況。任何對腳本中的'eval'的調用,這可能會產生與標籤外部的額外字符相同的效果...... – DaveRandom