dongluyi5123 2015-06-30 11:16
浏览 71

PHP:使用php中的curl通过microsoft dynamics crm将文件上传到sharepoint

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>
  • 写回答

1条回答 默认 最新

  • 普通网友 2015-07-01 18:45
    关注

    you are getting the errors because you need to authenticate to SharePoint. Are you using SharePoint Online or On Premises. I don't think it will be possible for you to use PHP for the solution, unless you can handle with custom code with the URL redirects when you authenticate to O365.

    I had a similar requirement, using Excel to upload to SharePoint and I designed VBA code to connect to SharePoint online, it was hard to maintain and it broke. I recommend you to create a .NET app were you pass the information i.e. (document library, source folder, user name, password, sharepoint site url) and that will work.

    I have Microsoft.SharePoint,Microsoft.SharePoint.Client, Microsoft.SharePoint.Client.Publishing and Microsoft.SharePoint.Client.Runtime in project references on Visual Studio and it works like charm.

    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧