0
當我問我的問題(問題)時,我認爲我的解釋並不乾淨。 我有一個項目PHP,我沒有本地環境,我在線工作:我通過Netbeans更改我的文件,我部署它,但未在本地進行測試。我的服務器是production.My數據庫(MySQL - phpMyadmin)的服務器也。 我將數據從我的磁盤導入到項目中。然後PHP通過HighChart開發它。用戶可以根據多種選擇(日期,城市,客戶等)查看這些數據,最後他可以將最終結果下載到文件csv中。 這裏的問題我不能下載所有的數據,例如:在Chart 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();
我希望這一次我的解釋是乾淨的,你能幫忙嗎?
謝謝。我會嘗試。 – sirine
它產生這樣的錯誤:在Export.php中的UndefinedFunctionException第39行:試圖從命名空間「Floose \ Export」調用函數「array_to_csv」。致命錯誤:在第39行調用未定義的函數Floose \ Export \ array_to_csv()在/home/outils/FLOOSE/FlooseDev/src/Export/Export.php中。 – sirine
我在這裏添加了它,但是在靜態中:public function __construct(array $ dataIN){ $ this - > _ dataIN = $ dataIN; $ this-> setFilepath(); $ this-> prepareFile(); $ this-> array_to_csv($ array,$ download); } – sirine