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