提问人:andreas 提问时间:10/31/2023 更新时间:10/31/2023 访问量:33
通过 PHP/curl 将文件移动到 SharePoint
move file to sharepoint via php/curl
问:
我使用以下 php 代码将 html 文件上传到 sharepoint:
$the_file = file_get_contents("".realpath(dirname(__FILE__))."/<file_name>.htm");//Note: the file already exists in the dir
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: multipart/form-data"));
curl_setopt($ch, CURLOPT_USERPWD, "<usr>:<pass>");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/20100101 Firefox/6.0Mozilla/4.0 (compatible;)");
curl_setopt($ch, CURLOPT_URL, "https://<xxxx>.sharepoint.com/sites/<xxx>/Shared%20Documents/Forms/AllItems.aspx");
curl_setopt($ch, CURLOPT_POST, true);
$post = array('file_contents' => "the_file");
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
if(curl_errno($ch)) {
echo json_encode('Error: ' . curl_error($ch));
}
else {
echo ($response);
}
curl_close($ch);
一切看起来都不错,$response给了我:
<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="https://<xxxx>.sharepoint.com/sites/<xxxx>/_layouts/15/Authenticate.aspx?Source=%2Fsites%2F<xxx>%2FShared%20Documents%2FForms%2FAllItems%2Easpx">here</a>.</h2>
</body></html>
但是当我进入 sharepoint(通过单击上面的链接)时,没有文件?!的痕迹
有人可以告诉我我做错了什么或错过了什么吗?
谢谢 安德烈亚斯
根据输出消息,我预计文件已上传,但事实并非如此?!
答: 暂无答案
评论