can anyone help to correct my script to Post multipart/form-data Thanks. $srand = substr(md5(rand(0,32000)),0,10); $aform = "----$srand\r\n"; $submitdata = $aform; $submitdata .= "Content-Disposition: form-data; name=\"title\"\r\n\r\n"; $submitdata .= "$title"; $submitdata .= "\r\n".$aform; $submitdata .= "Content-Disposition: form-data; name=\"bodytext\"\r\n\r\n"; $submitdata .= "$body"; $submitdata .= "\r\n"."----$srand"."--\r\n"; $postdata = $submitdata; $posturl = "http://test.com/submit.php"; $ch = curl_init($posturl); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "Content-Type: multipart/form-data; boundary=--$srand"); curl_setopt($ch, CURLOPT_POST ,1); curl_setopt($ch, CURLOPT_POSTFIELDS ,$postdata); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,0); curl_setopt($ch, CURLOPT_COOKIE, $mycookies); curl_setopt($ch, CURLOPT_HEADER ,1); // DO NOT RETURN HTTP HEADERS curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1); // RETURN THE CONTENTS OF THE CALL $return = curl_exec($ch); curl_close($ch); Code (markup):
I've been searching the whole freaking internet on how to emulate multipart/form-data posting with Curl... and nothing. Finally, found this - a dead solo-post that, apparently, solved all problems. Thanks.
unfortunately it didn't solve it for me, is all the code above necessary to do a multipart/form-data post (but not posting a file)? i've gone over and over my code but it won't post the form-data at all.
I'll admit I didn't read the whole post, but I have something on my website that will help people trying to use cURL with file uploads: cURL multipart from data file upload.