2012-12-28 114 views
-2

可能重複:
Reference - What does this error mean in PHP?錯誤日誌文件FEOF()與fgets()PHP

我有如下的PHP代碼:

<?php 
$PMTA = $_GET['PMTA']; 
//Get current date 
$date = date('Y-m-d'); 
// Declare variables 
$chart = array(); 
$title = ""; 
$domain = ""; 
$total = array(); 
$fail = array(); 
$cate = array(); 
$orderChart = array(); 
$container =""; 
$dormain_str = array(); 
// End declare variable 

//Use switch for getting the text files     
    switch($PMTA){ 
     case 1: 

      if(file_exists('../pmta/stats_domain_emetteur_recepteur.unitead.info.'.$date.'.txt')) 
      { 
       $file = '../pmta/stats_domain_emetteur_recepteur.unitead.info.'.$date.'.txt'; 
      } 
      else 
      { 
       $file = 'file_exits/stats_domain_sender_blank.txt'; 
      } 
      break; 
     case 2: 

      if(file_exists('../pmta/stats_domain_emetteur_recepteur.frdcrp.com.'.$date.'.txt')) 
      { 
       $file = '../pmta/stats_domain_emetteur_recepteur.frdcrp.com.'.$date.'.txt'; 
      } 
      else 
      { 
       $file = 'file_exits/stats_domain_sender_blank.txt'; 
      } 
      break; 
     case 3: 

      if(file_exists('../pmta/stats_domain_emetteur_recepteur.affinitead.net.'.$date.'.txt')) 
      { 
       $file = '../pmta/stats_domain_emetteur_recepteur.affinitead.net.'.$date.'.txt'; 
      } 
      else 
      { 
       $file = 'file_exits/stats_domain_sender_blank.txt'; 
      } 
      break; 
     case 4: 

      if(file_exists('../pmta/stats_domain_emetteur_recepteur.switchcall.com.'.$date.'.txt')) 
      { 
       $file = '../pmta/stats_domain_emetteur_recepteur.switchcall.com.'.$date.'.txt'; 
      } 
      else 
      { 
       $file = 'file_exits/stats_domain_sender_blank.txt'; 
      } 
      break; 
     case 5: 

      if(file_exists('../pmta/stats_domain_emetteur_recepteur.unitead.eu.'.$date.'.txt')) 
      { 
       $file = '../pmta/stats_domain_emetteur_recepteur.unitead.eu.'.$date.'.txt'; 
      } 
      else 
      { 
       $file = 'file_exits/stats_domain_sender_blank.txt'; 
      } 
      break; 

    } 

       // Open the file and read data 
       $files = fopen($file,'r'); 
       // Start i = 0 
       $i = 0; 
       // Check for the end of file has been reached,if have any error or end of file it will return true, other will return false 
       while(!feof($files)){ 
        // It breaks the string in file that seperate by ; into array, so $data will become an array 
        $data = explode(";",fgets($files)); 
        // Determind wheather the data is not empty or not 
        if(!empty($data[6])){ 
         $domain = $data[6]; 
          if(!empty($_POST['txt_order_blue'])){          
           $orderChart[$domain][] =array("success" => (100 - $data[9]),"fail" =>(float)$data[9],"cate" => $data[5]);          
          } 
           // Else if click on button order by % failed   
          else{ 
           $orderChart[$domain][] =array("fail" =>(float)$data[9],"success" => (100 - $data[9]),"cate" => $data[5]); 
          }        
         $i++; 

        } 

       } 

?> 

當我在本地運行它工作正常,但是當我在服務器上運行它時,它顯示消息

[Thu Dec 27 09:12:37 2012] [error] [client 103.23.136.12] PHP Warning: feof() expects parameter 1 to be resource, boolean given in /home/uniteadpro/www/kama/stats/unitead_chart/bar_chart_ratio_recepteur_emetteur.php on line 89 

而且

[Thu Dec 27 09:12:37 2012] [error] [client 103.23.136.12] PHP Warning: fgets() expects parameter 1 to be resource, boolean given in /home/uniteadpro/www/kama/stats/unitead_chart/bar_chart_ratio_recepteur_emetteur.php on line 90, referer: http://www.unitead.pro/kama/stats/unitead_chart/ 

在日誌文件中。
我不知道如何解決這個問題。

+4

你*不*處理錯誤。檢查'fopen($ file)'是否成功,然後將其作爲文件句柄傳遞。 – DCoder

回答

0

文件「file_exits/stats_domain_sender_blank.txt」是否存在於與「bar_chart_ratio_recepteur_emetteur.php」相同的位置上。

我想你的兩個文件必須位於「/ home/uniteadpro/www/kama/stats/unitead_chart /」位置。對於第二個錯誤,只需刪除while循環。