2015-06-20 25 views
2

我有一個問題,因爲我更新我的PHP版本5.4.41。php頭<! - 核心錯誤 - >和文件中斷

我使用php 5.4.41在nginx服務器上運行。

我已經做了一個php代碼,允許我檢索一個文件並下載它。但是,因爲我更新了我的php代碼,所有我想下載的文件都被破壞了。所以我上傳一個txt文件並查看發生了什麼。

EX:如果我上傳的文本文件測試裏面後,我下載它,它會成爲

<!--core error-->test 

這裏的完整代碼

<?php 

require_once("include.php"); 
if(!xml2php("customer")) { 
$smarty->assign('error_msg',"Error in language file"); 
} 

//Grab the key from the url 
$key = $VAR['key']; 

if ($VAR['escape'] == 1) { 

if (isset($key)) { 

$q = "SELECT * FROM ".PRFX."TABLE_CUSTOMER_BACKUP WHERE  CUSTOMER_BACKUP_KEY=".$db->qstr($key); 

if(!$rs = $db->Execute($q)) { 
    force_page('core', 'error&error_msg=MySQL Error: '.$db- >ErrorMsg().'&menu=1&type=database'); 
    exit; 
    } else { 

    $customer_backup_filename = $rs->fields['CUSTOMER_BACKUP_FILENAME']; 
    $customer_backup_ext = $rs->fields['CUSTOMER_BACKUP_EXT']; 
    $customer_backup_file_link = $rs->fields['CUSTOMER_BACKUP_FILE_LINK']; 
    $customer_backup_filetype = $rs->fields['CUSTOMER_BACKUP_FILETYPE']; 

    } 
     if(empty($customer_backup_file_link)){ 

     force_page('core', 'error&error_msg=This key is not valid'); 
     exit; 
     } 

} else { 
    force_page('core', 'error&error_msg=This key is not valid'); 
    exit; 
    } 

$fakeFileName= $customer_backup_filename.".".$customer_backup_ext; 

$file = $customer_backup_file_link; 



if (isset($customer_backup_file_link, $customer_backup_ext,  $customer_backup_filename, $customer_backup_filetype) &&  file_exists($customer_backup_file_link)){ 
    ignore_user_abort(true); 
    set_time_limit(0); // disable the time limit for this script 

    header("Cache-Control: public"); 
    header("Content-Description: File Transfer"); 
    header("Content-Type: ".$customer_backup_filetype); 
    header("Content-Disposition: attachment; filename=".$fakeFileName); 
    header("Content-Length: ".filesize($file)); 
    header("Content-Transfer-Encoding: binary"); 

    readfile($file); 

} else { 
    force_page('core', 'error&error_msg=There was a problem downloading your file. Please contact your administrator.'); 
    exit; 
} 

} else { 
force_page('core', 'error&error_msg=There was a problem downloading your file. Please contact your administrator.'); 
exit; 
} 

$smarty->display('customer'.SEP.'download.tpl'); 

//exit; 

?> 

我發現,如果我把//在

header("Content-Type: ".$customer_backup_filetype); 
header("Content-Disposition: attachment; filename=".$fakeFileName); 

要忽略它,文件將顯示在到瀏覽器沒有問題

我需要一些幫助我一直在這個問題上工作了2天,並沒有發現任何東西。

更新:

我發現,如果我試圖逃跑Smarty模板引擎,它不會工作同樣的問題。但是,如果我加載smarty模板引擎,文本將顯示沒有錯誤。

http://www.exemple.com/index.php?page=customer:download&key=1414830421&escape=1 //逃離Smarty模板引擎

+1

你肯定**的文件將顯示在瀏覽器沒有問題**?這可能是瀏覽器僅僅隱藏了視圖中的內容。畢竟這是一個JavaScript語法類型的評論? – Fluffeh

+0

是的,我確定我運行了一些測試,而不是下載文件,它會顯示文本到文件中,我嘗試多次,所有的單詞都在那裏。 –

回答

0

我忘記把代碼

ob_clean(); 
    flush(); 
0

<!--core error-->有前發起一些地方:

readfile($file); 

因爲這是你的內容「測試」被寫入線,後顯示它。

我的猜測是,該源爲之一:

  • include.php
  • xml2php()
  • $ DB->執行()

也許你可以將額外的輸出添加到您的代碼中,以將其縮小到行,<!--core error-->被寫入。