Hi All,
I'm pretty confused with this one. I'm new to CURL, and I'm trying to use to to post a file to a server. I'm getting the failed creating formpost data error, and after some research I've found that this is a read error. Basically the file isn't where I'm specifying it. I'm not sure why its not there. Any help is welcome!
$filename = $_FILES['activity_doc']['name'];// Name of the file (including file extension).
$path = __DIR__ . '/' . $filename;
$trimmed = ltrim($path, '/');
$post = array(
"activity_doc"=>"@$trimmed",
);
print_r($post);
if (is_uploaded_file($_FILES['activity_doc']['tmp_name'])) {
echo "File ". $_FILES['activity_doc']['name'] ." uploaded successfully.\n";
} else {
echo "Error occurred, file uploaded unsuccessful";
}
$upload_path = 'https://uploadpath
//Curl session initialized
$session = curl_init();
curl_setopt($session, CURLOPT_HEADER, 0);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($session, CURLOPT_VERBOSE, 1);
curl_setopt($session, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
curl_setopt($session, CURLOPT_URL, $upload_path);
curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($session, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($session, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($session, CURLOPT_USERPWD, 'username:password');
curl_setopt($session, CURLOPT_POST, true);
//curl_setopt($session, CURLOPT_HTTPHEADER, array(
//"Content-Type: image/pdf",
// ));
curl_setopt($session, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($session);
print_r($response);
print_r(curl_error($session));
$req = new SimpleXMLElement($response);
curl_close($session);
}