I am trying to upload files to the microsoft dynamics crm using php, for this I have integrated microsoft sharepoint to the crm. I have used curl for uploading the file to the sharepoint via crm but am getting 411 or 401 http error while executing the curl script.i am new to curl.Please help
<?php
ini_set('display_errors','On');
error_reporting(E_ALL);
if(isset($_POST['submit']) ) {
$process = curl_init();
$username = 'xxx';
$password = 'xxx';
$filename = $_FILES['ecosFile']['name'];
$filedata = $_FILES['ecosFile']['tmp_name'];
$filesize = $_FILES['ecosFile']['size'];
$post = array('file' => new CurlFile($filedata), "filename" => $filename);
print_r($post);
curl_setopt($process, CURLOPT_URL, 'https://crmsharepoint.XXX/sites/xxx/application/Forms/?RootFolder=xxx');
curl_setopt($process, CURLOPT_HEADER, 1);
curl_setopt($process, CURLOPT_HTTPHEADER, array('Content-Type:multipart/form-data', 'Content-Length:50'));
curl_setopt($process, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
curl_setopt($process, CURLOPT_POSTFIELDS, $post);
curl_setopt($process, CURLOPT_INFILESIZE, $filesize);
curl_setopt($process, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($process, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($process, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($process);
$resultStatus = curl_getinfo($process);
curl_close($process);
echo '<pre>';print_r($resultStatus);
if($resultStatus['http_code'] == 200) {
echo "hi".$response;
} else {
echo 'Call Failed '.print_r($resultStatus);
}
}
?>
<div>
<form action="testingcrm.php" enctype="multipart/form-data" method="post">
<input type="file" name="ecosFile" id="ecosFile">
<input type="submit" name="submit" value="Upload">
</form>
</div>