I'm working on a script that needs to post a file to another script. I'm using curl to do it at the moment which works fine when the file is available locally on the filesystem but I now need to post from an open stream and can't see a way to do it with curl, my current code is:
Code: Select all
$formvars = array();
$formvars["field1"] = "xxxxx";
$formvars["field2"] = "xxxxx";
$formvars["imagedata"] = "@$filepath";
$ch = curl_init($posturl);
curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 180);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $formvars);Is there a way to do this with curl? If not, is there an alternative class which could do it? If not, I shall start creating my own.
Thanks.