2012-10-21 66 views
1

很奇怪,我的代碼在我的本地運行,但是當我部署它遠程服務器上。它得到了T_IF錯誤。該代碼是如下:PHP,意外T_IF,在線XXX XXX的文件預計T_FUNCTION

的XXX行是圍繞:$實驗[ 'import_result'] = TRUE;

private function do_import($file_info, $ih_id){ 

    $this->load->library("MY_PHPExcel"); 
    $inputFileName = $file_info['full_path']; 
    $sheetNames = array('General','Gas', 'Sample', 'Mass Gain', 'Cr'); 

    /** Identify the type of $inputFileName **/ 
    $inputFileType = PHPExcel_IOFactory::identify($inputFileName); 
    /** Create a new Reader of the type that has been identified **/ 
    $objReader = PHPExcel_IOFactory::createReader($inputFileType); 
    /** Advise the Reader that we only want to load cell data **/ 
    $objReader->setReadDataOnly(true); 
    /** Advise the Reader of which WorkSheets we want to load **/ 
    $objReader->setLoadSheetsOnly($sheetNames); 
    /** Tell the Reader that we want to use the Read Filter **/ 
    //$objReader->setReadFilter($filterSubset); 
    /** Load $inputFileName to a PHPExcel Object **/ 
    $objPHPExcel = $objReader->load($inputFileName); 
    $sheetCount=$objPHPExcel->getSheetCount(); 

    $experiment = array(); 
    for($index = 0; $index<$sheetCount; $index++){ 
     $objPHPExcel->setActiveSheetIndex($index); 
     $sheetName = $objPHPExcel->getActiveSheet()->getTitle(); 
     if($sheetName == 'General'){ 
      $experiment['general'] = $this->read_general($objPHPExcel, $index, 1); 
     }elseif($sheetName == 'Sample'){ 
      $experiment['sample'] = $this->read_sample($objPHPExcel, $index, 1); 
     }elseif($sheetName == 'Gas'){ 
      $experiment['gas'] = $this->read_gas($objPHPExcel, $index, 1); 
     }elseif($sheetName == 'Mass Gain'){ 
      $experiment['mass'] = $this->read_mass($objPHPExcel, $index, 1); 
     }elseif($sheetName == 'Cr'){ 
      $experiment['cr'] = $this->read_cr($objPHPExcel, $index, 1); 
     } 
    } 


    //if there is format error 
    foreach($experiment as $sheet){ 
     if(isset($sheet) && !empty($sheet)){ 
      if(isset($sheet['error']) && !empty($sheet['error'])){ 
       $experiment['import_result'] = FALSE; 
       break 1; 
      }elseif(isset($sheet['validation']['validation']) && $sheet['validation']['validation'] == 0){ 
       $experiment['import_result'] = FALSE; 
       break 1; 
      }else{ 
       $experiment['import_result'] = TRUE; 
       break 1; 
      } 
     } 
    } 

    if($experiment['import_result']){//there is no format error, proceed to import 
     //do import into DB 
     $import_flag = 0; 
     $post_data = $this->input->post(); 

     if(isset($post_data['import_radio']) && $post_data['import_radio'] == 1){//new 
      $import_flag = $this->m_import->import_experiment_new($experiment, $this->session->userdata('user_id'), $ih_id); 
     }elseif(isset($post_data['import_radio']) && $post_data['import_radio'] == 2){//update 
      //debug 
      //$this->firephp->log('update an existing experiment'); 
      $import_flag = $this->m_import->import_experiment_update($post_data['import_eid'], $experiment, $this->session->userdata('user_id'), $ih_id); 
     }else{//didn't choose a mode 
      return array('status'=>4, 'message'=>'Please select "new" or "update".'); 
     } 

     if($import_flag != 0){//import done ok 
      if($post_data['import_radio'] == 1){ 
       return array('status'=>1, 'message'=>'File has been successfully imported, the new experiment ID is '.$import_flag.'.'); 
      }else{ 
       return array('status'=>1, 'message'=>'File has been successfully imported, Experiment'.$import_flag.' has been updated.'); 
      } 
     }else{//validation ok, import fail 
      return array('status'=>2, 'message'=>'Something went wrong during the process of importing, please try again.'); 
     } 
    }else{ 
     //return experiment with errors which are to be presented in view 
     $return_error = array(); 
     $return_warning = array(); 
     foreach($experiment as $name => $sheet){ 
      if(isset($sheet['validation'])){ 
       foreach ($sheet['validation']['error'] as $item){ 
        array_push($return_error, $item); 
       } 
       foreach($sheet['validation']['warning'] as $item){ 
        array_push($return_warning, $item); 
       } 
      } 
     } 
     //if(!empty($temp_interval_match_error)){ array_push($return_error, $temp_interval_match_error); } 
     return array('status'=>3, 'message'=>'The file has invalid cells, please correct the file according to the following hints.', 
        'error' => $return_error, 'warning'=>$return_warning); 
    } 
}//end of fn do_import() 

請幫助找到問題所在。提前謝謝了。

+0

問題解決了。我通過塊刪除代碼塊,最後得出結論,當我上傳文件時,其中一條if語句被其上面的註釋意外地註釋掉了。我想這可能是關於服務器的錯誤。奇怪的。 – user1310312

回答

0

問題已解決。我通過塊刪除代碼塊,最後得出結論,當我上傳文件時,其中一條if語句被其上面的註釋意外地註釋掉了。我想這可能是關於服務器的錯誤。奇怪的。

0

不太可能,但可能的方式來引起你設置你的if聲明你的$experiment['import_result']以上。例如,如果$sheet未設置或爲空,$experiment['import_result']不會設置,因爲沒有else。嘗試添加額外的else {$experiment['import_result'] = FALSE;}

foreach($experiment as $sheet){ 
    if(isset($sheet) && !empty($sheet)){ 
     if(isset($sheet['error']) && !empty($sheet['error'])){ 
      $experiment['import_result'] = FALSE; 
     }elseif(isset($sheet['validation']['validation']) && $sheet['validation']['validation'] == 0){ 
      $experiment['import_result'] = FALSE; 
     }else{ 
      $experiment['import_result'] = TRUE; 
     } 
    } 
    else {$experiment['import_result'] = FALSE;} // added 
} 
+0

感謝您的快速回復。我通過逐塊地刪除代碼來計算出來。最後找到問題。在我的源代碼中,有幾行評論。不知道爲什麼當部署代碼時,if()語句之一意外地被註釋掉了。現在我使用/ ** /來註釋而不是//。它對我沒有任何影響。無論如何,修好了,謝謝你的幫助。 PS:我的遠程服務器是HostGator的 – user1310312

+0

請發帖回答自己和接受它,@ user1310312。 –

相關問題