form post to curl post
Posted: Thu Jan 13, 2011 9:50 am
HI,
I have a situation where i need to send a csv file to external site via post method - The first method i come up with is using form as shown below -
this works absolutely fine but problem with this is - user has to browse the file and then click ok to finish the task whereas i want it fully automated - as soon as this page runs - the form is submitted itself. So to overcome this issue - i come with equivalent curl option as shown below -
but this is not really working as i am getting blank page and it's not uploading the file to the external site.
Am i doing this curl bit correctly ? I am using the same method for initial request(to post few values and not file) and it works fine but just not working in this situation...
Any help would be greatly appreciated.
Thanks
I have a situation where i need to send a csv file to external site via post method - The first method i come up with is using form as shown below -
Code: Select all
<form name="file" enctype="multipart/form-data" method="post" action="http://server.com/abc/upload_data.php">
<input name=<?php echo $id ?>value="" type="file" size="30" /> <br />
<input name="profileName" value="<?php echo "testing"; ?>" />
<input type="submit" value="ok" />
Code: Select all
function datapost($URLServer,$postdata)
{
$agent = "Mozilla/5.0";
$cURL_Session = curl_init();
curl_setopt($cURL_Session, CURLOPT_URL,$URLServer);
curl_setopt($cURL_Session, CURLOPT_USERAGENT, $agent);
curl_setopt($cURL_Session, CURLOPT_POST, 1);
curl_setopt($cURL_Session, CURLOPT_POSTFIELDS,$postdata);
curl_setopt($cURL_Session, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cURL_Session, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec ($cURL_Session);
return $result;
}
$postdata = array();
$postdata['profileName'] = 'testing';
$postdata[$id] = ' ';
$postdata['file'] = '@'.'test/file/export/beta.csv';
$postdata['submit'] = urlencode('submit');
$abc= datapost("http://server.com/abc/upload_data.php",$postdata);
echo $abc;
Am i doing this curl bit correctly ? I am using the same method for initial request(to post few values and not file) and it works fine but just not working in this situation...
Any help would be greatly appreciated.
Thanks