Recreating http request with cURL incl. files
Posted
by Toby
on Stack Overflow
See other posts from Stack Overflow
or by Toby
Published on 2010-06-08T18:09:04Z
Indexed on
2010/06/08
18:12 UTC
Read the original article
Hit count: 177
I consistently get the error 'failed creating formpost data' from the below code, the same thing works perfectly on my local testing server, but on my shared host it throws the error.
The sample part is just to simulate building the array with both files and non-file data. Essentially all I'm trying to do here is redirect the same http request to another server, but I'm running into so many troubles.
$count=count($_FILES['photographs']['tmp_name']);
$file_posts=array('samplesample' => 'ladeda');
for($i=0;$i<$count;$i++) {
if(!empty($_FILES['photographs']['name'][$i])) {
$fn = genRandomString();
$file_posts[$fn] = "@".$_FILES['photographs']['tmp_name'][$i];
}
}
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,"http://myurl/wp-content/plugins/autol/rec.php");
curl_setopt($ch,CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch,CURLOPT_HEADER,TRUE);
curl_setopt($ch,CURLOPT_POST,TRUE);
curl_setopt($ch,CURLOPT_POSTFIELDS,$file_posts);
curl_exec($ch);
print curl_error($ch);
curl_close($ch);
© Stack Overflow or respective owner