【问题标题】:PHP : upload file to sharepoint via microsoft dynamics crm using curl in phpPHP:使用 php 中的 curl 通过 Microsoft Dynamics crm 将文件上传到共享点
【发布时间】:2015-06-30 11:16:17
【问题描述】:

我正在尝试使用 php 将文件上传到 microsoft dynamics crm,为此我已将 microsoft sharepoint 集成到 crm。我使用 curl 通过 crm 将文件上传到共享点,但在执行 curl 脚本时出现 411 或 401 http 错误。我是 curl 的新手。请帮助

<?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>

【问题讨论】:

  • 你找到了任何答案..我需要解决这个问题

标签: php sharepoint curl file-upload crm


【解决方案1】:

您收到错误是因为您需要对 SharePoint 进行身份验证。您使用的是 SharePoint Online 还是本地。我认为您不可能将 PHP 用于解决方案,除非您可以在向 O365 进行身份验证时处理带有 URL 重定向的自定义代码。

我有一个类似的需求,使用 Excel 上传到 SharePoint,我设计了 VBA 代码来连接到在线 SharePoint,它很难维护并且坏了。我建议您创建一个 .NET 应用程序,如果您传递了信息,即(文档库、源文件夹、用户名、密码、sharepoint 站点 url),这将起作用。

我在 Visual Studio 上的项目引用中有 Microsoft.SharePoint、Microsoft.SharePoint.Client、Microsoft.SharePoint.Client.Publishing 和 Microsoft.SharePoint.Client.Runtime,它的工作原理非常有魅力。

【讨论】:

    猜你喜欢
    • 2017-10-19
    • 2022-06-29
    • 1970-01-01
    • 2017-03-20
    • 2016-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-22
    相关资源
    最近更新 更多