  | 
		 		   | 
	  	    
          
            
			
	
			
			 
                สอบถามหน่อยครับ โค้ดด้านล่างผมทำการทดสอบบน Window ใช้ Appserv ในการทดสอบ 
มี error เกิดขึ้น 2 อย่าง คือ 1.fputcsv() expects parameter 2 to be array และ 
2.Maximum execution time of 30 seconds exceeded  
 
แต่ได้ข้อมูลออกมาถูกต้องทั้งหมด ประเด็นคือผมต้องการ export เป็น .csv file ไว้บน Linux 
เช่น เวลาผม execute # ./index.php  จากนั้นผมใช้ command  # ls -l เพื่อดูไฟล์ 
ผมจะพบไฟล์ .csv บน Linux 
 
 
Code (PHP) 
<?php
# Prepare the data to query
$data = array(
		'uid' => 'xxx', 
		'pass' => 'xxx',
		'cmd' => 'xxx',
		'sDate' => '20180723100000',
		'eDate' => '20180723110000'
);
# Create a connection format
$url = 'http://pro.mobileinnovation.asia:81/WFO/getRecord';
$postString = http_build_query($data, '', '&');
#1 uid=TDEM-0131-0002&pass=8m9z3U2g&cmd=getWRecord&sDate=20180723100000&eDate=20180723110000
#2 http://pro.mobileinnovation.asia:81/WFO/getRecord?uid=TDEM-0131-0002&pass=8m9z3U2g&cmd=getWRecord&sDate=20180723100000&eDate=20180723110000
// Prepare csv format on the header
header('Content-Type: text/csv; charset=utf-8');  
header('Content-Disposition: attachment; filename=data.csv');  
	$output = fopen("php://output", "w"); 
	
	// Prepare the header of CSV file
	fputcsv($output,
			array(
			'Car Number','Class Number','Record Time','Dstb Sum','Lat0','Lan0','Lat10','Lon10','Lat20','Lon20','Lat30','Lon30',
			'Lat40','Lon40','Lat50','Lon50','GPS','Direction','Speed','RecReserver1','Speed Avg','Speed Max','Speen Min','Rpm Avg',
			'Rpm Max','Rpm Min','Analog1 Avg','Analog1 max','Analog1 min','Analog2 Avg','Analog2 max','Analog2 min','Analog3 Avg',
			'Analog3 max','Analog3 min','Analog4 Avg','Analog4 max','Analog4 min','Digi Sw1','Digi Sw2','Digi Sw3','Digi Sw4','Fuel'
			));
			
// Get data by curl function
$ch = curl_init();
//curl_setopt ($ch, CURLOPT_PORT , 81);
curl_setopt($ch, CURLOPT_VERBOSE, true);
//curl_setopt ($ch, CURLOPT_PORT , 81);
curl_setopt($ch, CURLOPT_URL, $url);
//curl_setopt ($ch, CURLOPT_PORT , 81);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);
//put to CSV
	while($store = curl_exec ($ch))  
      {  
           fputcsv($output, $store);  
      }  
	  // close connection to TTI
	  curl_close ($ch);
	  //Close connection out put file
      fclose($output);  
//Next
?>
 
 
  Tag : MySQL, Linux, Apache, Appserv               
                        | 
           
          
            | 
			
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          2018-07-26 11:36:41 | 
                      By :
                          top8891 | 
                      View :
                          1273 | 
                      Reply :
                          1 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  |