PHP-SPO上载大文件-请求消息太大
我正在使用PHP-SPO()将文件从我的Web服务器上载到Sharepoint。它可以工作,但大型文件除外,我在其中收到消息“请求消息太大。服务器不允许Sharepoint中的消息大于2097152字节” 这是我目前的代码:PHP-SPO上载大文件-请求消息太大,php,sharepoint,Php,Sharepoint,我正在使用PHP-SPO()将文件从我的Web服务器上载到Sharepoint。它可以工作,但大型文件除外,我在其中收到消息“请求消息太大。服务器不允许Sharepoint中的消息大于2097152字节” 这是我目前的代码: $targetLibraryTitle = 'Backups/Chamilo/' . $chamiloCode . '/'; $parentFolder = $this->sharePointAPI->getWeb()->getFolderByServer
$targetLibraryTitle = 'Backups/Chamilo/' . $chamiloCode . '/';
$parentFolder = $this->sharePointAPI->getWeb()->getFolderByServerRelativeUrl(dirname($targetLibraryTitle));
$parentFolder->getFolders()->add(basename($targetLibraryTitle));
$this->sharePointAPI->executeQuery();
$targetList = $this->sharePointAPI->getWeb()->getLists()->getByTitle($targetLibraryTitle);
try {
$fileCreationInformation = new FileCreationInformation();
$fileCreationInformation->Content = file_get_contents($filePath);
$fileCreationInformation->Url = basename($filePath);
$uploadFile = $this->sharePointAPI->getWeb()
->getFolderByServerRelativeUrl($targetLibraryTitle)
->getFiles()
->add($fileCreationInformation);
$this->sharePointAPI->executeQuery();
} catch (\Exception $e) {
dd(__FILE__ . ' - regel: ' . __LINE__, $chamiloCode, $e->getMessage());
}
我知道这与Sharepoint设置的限制有关。但我找不到解决办法
请帮忙
蒂姆,所以我把它修好了。无法上载图形大于4MB的文件。 所以我用了这个脚本:
$subFolder = 'Chamilo/' . $chamiloCode;
$fileName = basename($filePath);
try {
$reqBody = [
'@microsoft.graph.conflictBehavior' => 'rename | fail | replace',
'description' => 'backup ' . $chamiloCode,
'fileSystemInfo' => ['@odata.type' => 'microsoft.graph.fileSystemInfo'],
'name' => $fileName,
];
$uploadSession = $this->graphClient->createRequest(
self::REQUEST_TYPE_POST,
self::APP_ENDPOINT_DRIVES
. '/' . self::SHAREPOINT_GROUP_IT_BACKUP_FOLDER_ID . '/root:/'
. $subFolder . '/' . $fileName
. ':/createUploadSession'
)
->attachBody($reqBody)
->setReturnType(Office365UploadSession::class)
->execute();
$handle = fopen($filePath, 'rb');
$fileSize = fileSize($filePath);
$chunkSize = 1024 * 1024 * 4;
$numberOfFragments = ceil($fileSize / $chunkSize);
while (!feof($handle)) {
$currentPosition = ftell($handle);
$contents = fread($handle, $chunkSize);
$nextPosition = ftell($handle);
$resp = $this->graphClient->createRequest(self::REQUEST_TYPE_PUT, $uploadSession->getUploadUrl())
->addHeaders(
[
'Connection' => 'keep-alive',
'Content-Length' => (strlen($contents)),
'Content-Range' => 'bytes ' . $currentPosition
. '-' . ($nextPosition - 1)
. '/' . $fileSize,
]
)
->setReturnType(Office365UploadSession::class)
->attachBody($contents)
->execute();
}
} catch (\Exception $e) {
$this->handleException($e);
}