Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion examples/SharePoint/file_examples.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function processFiles(SPList $list,$targetPath)
//approveFile($ctx,$file->ServerRelativeUrl);
$fileName = $targetPath . "/" . basename($file->ServerRelativeUrl);
downloadFile($ctx,$file->ServerRelativeUrl,$fileName);
//downloadFileAsStream($ctx,$file->ServerRelativeUrl,$fileName);
}
}

Expand Down Expand Up @@ -150,4 +151,17 @@ function downloadFile(ClientRuntimeContext $ctx, $fileUrl, $targetFilePath){
$fileContent = Office365\PHP\Client\SharePoint\File::openBinary($ctx,$fileUrl);
file_put_contents($targetFilePath, $fileContent);
print "File {$fileUrl} has been downloaded successfully\r\n";
}
}

function downloadFileAsStream(ClientRuntimeContext $ctx, $fileUrl, $targetFilePath) {
$fileUrl = rawurlencode($fileUrl);

$fp = fopen($targetFilePath, 'w+');
$url = $ctx->getServiceRootUrl() . "web/getfilebyserverrelativeurl('$fileUrl')/\$value";
$options = new \Office365\PHP\Client\Runtime\Utilities\RequestOptions($url);
$options->StreamHandle = $fp;
$ctx->executeQueryDirect($options);
fclose($fp);

print "File {$fileUrl} has been downloaded successfully\r\n";
}
9 changes: 8 additions & 1 deletion src/Runtime/Utilities/RequestOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function __construct($url, $headers = array(), $data = null, $methodType
$this->UserCredentials = null;
$this->Verbose = false;
$this->SSLVersion = null;
$this->StreamHandle = null;
}

public function toArray()
Expand All @@ -42,10 +43,10 @@ public function toArray()
'Verbose' => $this->Verbose,
'UserCredentials' => $this->UserCredentials,
'SSLVersion' => $this->SSLVersion,
'StreamHandle' => $this->StreamHandle,
];
}


public function addCustomHeader($name, $value)
{
if (is_null($this->Headers))
Expand Down Expand Up @@ -127,4 +128,10 @@ function ($k, $v) {
*/
public $SSLVersion;


/**
* @var resource
*/
public $StreamHandle;

}
2 changes: 2 additions & 0 deletions src/Runtime/Utilities/Requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ private static function init(RequestOptions $options)
//set Post Body
if(isset($options->Data))
curl_setopt($ch, CURLOPT_POSTFIELDS, $options->Data);
if(is_resource($options->StreamHandle))
curl_setopt($ch, CURLOPT_FILE, $options->StreamHandle);
$options->addCustomHeader("content-length",strlen($options->Data));
//custom HTTP headers
if($options->Headers)
Expand Down