tags:

views:

10

answers:

1

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);
A: 

A quick google turns up this:

http://www.phpfreaks.com/forums/index.php?topic=125783.0

Looks like you probably need to add some additional path info to this line:

$file_posts[$fn] = "@".$_FILES['photographs']['tmp_name'][$i];

cURL may not know which directory to look for $_FILES['photographs']['tmp_name'][$i] in.

Frank Farmer
I've seen that page, and I've tried adding additional path info. So far no luck.
Toby