diff --git a/examples/SharePoint/Files/DownloadFileAsContent.php b/examples/SharePoint/Files/DownloadFileAsContent.php index ee9e5901..2bb59e27 100644 --- a/examples/SharePoint/Files/DownloadFileAsContent.php +++ b/examples/SharePoint/Files/DownloadFileAsContent.php @@ -5,10 +5,10 @@ use Office365\SharePoint\ClientContext; -$settings = include('../../Settings.php'); -require_once '../vendor/autoload.php'; +require_once '../../vendor/autoload.php'; +$settings = include('../../../tests/Settings.php'); -$sourceFileUrl = rawurlencode("/Shared Documents/SharePoint User Guide.docx"); +$sourceFileUrl = "/Shared Documents/SharePoint User Guide.docx"; $targetPath = "../data/SharePoint User Guide.docx"; $appCreds = new ClientCredential($settings['ClientId'], $settings['ClientSecret']); diff --git a/examples/SharePoint/Files/DownloadFileAsStream.php b/examples/SharePoint/Files/DownloadFileAsStream.php index 57ab92f3..22f8b847 100644 --- a/examples/SharePoint/Files/DownloadFileAsStream.php +++ b/examples/SharePoint/Files/DownloadFileAsStream.php @@ -4,8 +4,8 @@ use Office365\SharePoint\ClientContext; use Office365\SharePoint\File; -$settings = include('../../Settings.php'); -require_once '../vendor/autoload.php'; +require_once '../../vendor/autoload.php'; +$settings = include('../../../tests/Settings.php'); $appCreds = new ClientCredential($settings['ClientId'], $settings['ClientSecret']); $ctx = (new ClientContext($settings['Url']))->withCredentials($appCreds); @@ -20,8 +20,7 @@ try { $fileName = join(DIRECTORY_SEPARATOR, [sys_get_temp_dir(), $file->getName()]); $fh = fopen($fileName, 'w+'); - $file->download($fh); - $ctx->executeQuery(); + $file->download($fh)->executeQuery(); fclose($fh); print "File {$fileName} has been downloaded successfully\r\n"; } catch (Exception $e) { diff --git a/src/SharePoint/File.php b/src/SharePoint/File.php index 66c15e41..aa6d2af6 100644 --- a/src/SharePoint/File.php +++ b/src/SharePoint/File.php @@ -190,7 +190,7 @@ public function recycle() public static function openBinary(ClientRuntimeContext $ctx, $serverRelativeUrl) { $serverRelativeUrl = rawurlencode($serverRelativeUrl); - $url = $ctx->getServiceRootUrl() . "web/getfilebyserverrelativeurl('{$serverRelativeUrl}')/\$value"; + $url = $ctx->getServiceRootUrl() . "/web/getfilebyserverrelativeurl('{$serverRelativeUrl}')/\$value"; $options = new RequestOptions($url); $options->TransferEncodingChunkedAllowed = true; $response = $ctx->executeQueryDirect($options); @@ -210,7 +210,7 @@ public static function openBinary(ClientRuntimeContext $ctx, $serverRelativeUrl) public static function saveBinary(ClientRuntimeContext $ctx, $serverRelativeUrl, $content) { $serverRelativeUrl = rawurlencode($serverRelativeUrl); - $url = $ctx->getServiceRootUrl() . "web/getfilebyserverrelativeurl('{$serverRelativeUrl}')/\$value"; + $url = $ctx->getServiceRootUrl() . "/web/getfilebyserverrelativeurl('{$serverRelativeUrl}')/\$value"; $request = new RequestOptions($url); $request->Method = HttpMethod::Post; $request->ensureHeader('X-HTTP-Method', 'PUT');