I'm new to the PHP game and I'm working on a one off project. I'm trying to write a php file that will (1) submit a url query to a website, (2) open the downloaded csv file and (3) save it to a my sql database. So far I've gotten stages 2 and 3 to work. I'm not sure how to get stage 1 to work.
the following is the url which causes a csv file to be downloaded:
http://www.eirgrid.com/operations/syste ... eneration/
I've no idea where to go with this. One approach I was messing with was a curl implementation along the lines of:
Code: Select all
$url='http://www.eirgrid.com/operations/systemperformancedata/download.jsp';
$fields=array(
'download'=>'Y',
'startdate'=>'31/07/2010',
'enddate'=>'31/07/2010',
'proc'=>'data_pack.getwindgenforadayt4',
'templatename'=>'Wind%20Generation',
'columnnames'=>'Time,Wind%20Generation%20MW,Forecast%20MW' ,
'prevurl'=>'http://www.eirgrid.com/operations/systemperformancedata/windgeneration/'
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
echo $fields_string.'<p></p>';
$fields_string=rtrim($fields_string,'&');
echo $fields_string.'<p></p>';
$ch = curl_init();
echo $ch;
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
// grab URL and pass it to the browser
$result=curl_exec($ch);
var_dump($result);
// close cURL resource, and free up system resources
curl_close($ch);Thanks!