Omni
06-27-2007, 03:31 PM
Hi all, been at this for the past 6 hours and it's probably something simple for a php expert.
Problem
I am trying to use curl to emulate submitting an html form using POST method. So far I have been able to get it working for all forms. The only exception is one that also needs to upload a file. My understanding is that this is a multi part POST.
$params="key1=data1&key2=data2&key3=data3";
$tempfile = "filename.ext";
$ch=curl_init();
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS,array('csv_file'=>"@$tempfile"));
curl_setopt($ch, CURLOPT_POSTFIELDS,array($params));
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_COOKIE, 1);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result=curl_exec ($ch);
curl_close ($ch);
echo $result;
This didn't work though. I've tried many iterations of formatting CURLOPT_POSTFIELDS to no avail.
Any ideas?
Problem
I am trying to use curl to emulate submitting an html form using POST method. So far I have been able to get it working for all forms. The only exception is one that also needs to upload a file. My understanding is that this is a multi part POST.
$params="key1=data1&key2=data2&key3=data3";
$tempfile = "filename.ext";
$ch=curl_init();
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS,array('csv_file'=>"@$tempfile"));
curl_setopt($ch, CURLOPT_POSTFIELDS,array($params));
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_COOKIE, 1);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result=curl_exec ($ch);
curl_close ($ch);
echo $result;
This didn't work though. I've tried many iterations of formatting CURLOPT_POSTFIELDS to no avail.
Any ideas?
