2017-04-05 14 views
0

私は私の質問(問題)を聞いたときに私の説明できれいではなかったと思います。 私はプロジェクトPHPを持っていますが、私はローカルエンバイロメントを持っていません。私はオンラインで作業しています:Netbeans経由でファイルを変更し、ローカルでテストせずに展開します。私のサーバーは、生産中です。私のデータベース(MySQL - phpMyadmin)も、サーバー上にあります。 私のディスクからプロジェクトにデータをインポートします。その後、PHPはHighChart経由でそれを悪用します。ユーザーは多数の選択肢(日付、都市、顧客など)ごとにこれらのデータを見ることができ、最終的にこの最終結果をファイルcsvにダウンロードすることができます。 ここでは、すべてのデータをダウンロードできないという問題があります。たとえば、チャート14MillionのTurnoverディスプレイでは、ファイルcsvでは回転数がより少なく表​​示されます。PHPからファイルをインポート/エクスポート

この次に私のコード:

class Export{ 
    private $_dataIN=[]; 
    private $_author; 
    private $_filepath; 

    public function __construct(array $dataIN) { 
     $this->_dataIN = $dataIN; 
     $this->setFilepath(); 
     $this->prepareFile(); 
    } 
    public function setFilepath() { 
     $date = new \DateTime(); 
     $this->_filepath='../DATA/ExportFiles/ExportData'.$date->getTimestamp(); 
    } 
    public function prepareFile(){ 
     $file = fopen($this->_filepath, 'w'); 
     fputcsv($file, array('Piece', 'Client', 'Libelle Client', 'Facturation','OTP','Typcde','Cdecli','Cdesap','Article','Designation','Dev','Montant_fac_dev_ht','Montant_fac_eur','Avion','Nature','Repsite','Zone','LRU','Contract'),';');   
     foreach ($this->_dataIN as $key => $statement) { 
      fputcsv($file, array($statement->getId(), $statement->getCustomerId(), $statement->getCustomerName(), $statement->getDate(), $statement->getOTP(), $statement->getCdetype(), $statement->getCdecustomer(), $statement->getSAPcode(), $statement->getArticle(), $statement->getDesigniation(), $statement->getCurrency(), $statement->getAmount(), $statement->getAmountEur(), $statement->getAircraft(), $statement->getNature(), $statement->getRepsite(), $statement->getZone(), $statement->getLru(),$statement->getContract()),';'); 
     } 
    } 

    public function download() {   

     header('Content-Description: File Transfer'); 
     header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');//octet-stream' 
     header('Content-Disposition: attachment; filename='.basename($this->_filepath).'.csv'); 
     header('Expires: 0'); 
     header('Cache-Control: must-revalidate'); 
     header('Pragma: public'); 
     header('Content-Length: ' . filesize($this->_filepath) . 'Giga'); //Kilo 
     readfile($this->_filepath); 
     exit(); 

私は、この時間は私の説明がクリーンであることを願って、あなたは助けることができますか?

答えて

1

保存せずに、次のように使用することをお勧め:

public function __construct($dataIN = array()) { 
    $this->_dataIN = $dataIN; 
    $this->prepareFile(); 
} 

public function prepareFile(){ 

    $header[] = array('Piece', 'Client', 'Libelle Client', 'Facturation','OTP','Typcde','Cdecli','Cdesap','Article','Designation','Dev','Montant_fac_dev_ht','Montant_fac_eur','Avion','Nature','Repsite','Zone','LRU','Contract');   

    $data = array(); 

    foreach ($this->_dataIN as $key => $statement) { 
     $data[] = array($statement->getId(), $statement->getCustomerId(), $statement->getCustomerName(), $statement->getDate(), $statement->getOTP(), $statement->getCdetype(), $statement->getCdecustomer(), $statement->getSAPcode(), $statement->getArticle(), $statement->getDesigniation(), $statement->getCurrency(), $statement->getAmount(), $statement->getAmountEur(), $statement->getAircraft(), $statement->getNature(), $statement->getRepsite(), $statement->getZone(), $statement->getLru(),$statement->getContract()); 
    } 

    $final_data = array_merge($header, $data); 

    $this->array_to_csv($final_data, 'report.csv'); 
} 


function array_to_csv($array, $download = "") 
{ 
    if ($download != "") 
    {  
     header('Content-Description: File Transfer'); 
     header("Content-type: application/vnd.ms-excel"); 
     header('Content-Disposition: attachement; filename="' . $download . '"'); 
     header('Content-Transfer-Encoding: binary'); 
    }   

    ob_start(); 
    $f = fopen('php://output', 'w') or show_error("Can't open php://output"); 
    $n = 0;   
    foreach ($array as $line) 
    { 
     $n++; 
     if (! fputcsv($f, $line)) 
     { 
      show_error("Can't write line $n: $line"); 
     } 
    } 
    fclose($f) or show_error("Can't close php://output"); 
    $str = ob_get_contents(); 
    ob_end_clean(); 

    if ($download == "") 
    { 
     return $str;  
    } 
    else 
    {  
     print "\xEF\xBB\xBF"; // UTF-8 BOM 
     print $str; 
    }   
} 
+0

ありがとうございました。やってみます。 – sirine

+0

これは次のようなエラーになります:UndefinedFunctionException Export.php行39:名前空間 "Floose \ Export"から関数 "array_to_csv"を呼び出そうとしました。致命的なエラー:39行目の/home/outils/FLOOSE/FlooseDev/src/Export/Export.phpの未定義の関数Floose \ Export \ array_to_csv()を呼び出してください。 – sirine

+0

ここに静的に追加しました:public function __construct(array $ dataIN){ $ this - > _ dataIN = $ dataIN; $ this-> setFilepath(); $ this-> prepareFile(); $ this-> array_to_csv($ array、$ download); } – sirine

関連する問題