January 27, 2005

using php and curl to do an html file post

after scouring the internet to find out how to do multipart post operations and finding nothing nothing, i decided to save someone else some time. the trick is that @ before the file name.

$fullflepath = 'C:\temp\test.jpg';
$upload_url = 'http://www.example.com/uploadtarget.php';
$params = array(
	'photo'=>"@$fullfilepath",
	'title'=>$title
);		

$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_URL, $upload_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($ch);
curl_close($ch);
Posted by drewish at January 27, 2005 06:27 AM

Trackback Pings

TrackBack URL for this entry:
http://drewish.com/mt/mt-tb.cgi/1281

Comments

Post a comment

Thanks for signing in, . Now you can comment. (sign out)

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)


Remember me?


Creative Commons License xml feed