Skip to content

Commit 9d6c58a

Browse files
authored
Merge pull request #59 from blizzz/curl-options
add method to set curl options
2 parents 04e6adc + 5f591f9 commit 9d6c58a

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

examples/SharePoint/file_examples.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ function processFiles(SPList $list,$targetPath)
7474
//approveFile($ctx,$file->ServerRelativeUrl);
7575
$fileName = $targetPath . "/" . basename($file->ServerRelativeUrl);
7676
downloadFile($ctx,$file->ServerRelativeUrl,$fileName);
77+
//downloadFileAsStream($ctx,$file->ServerRelativeUrl,$fileName);
7778
}
7879
}
7980

@@ -162,4 +163,17 @@ function downloadFile(ClientRuntimeContext $ctx, $fileUrl, $targetFilePath){
162163
$fileContent = Office365\PHP\Client\SharePoint\File::openBinary($ctx,$fileUrl);
163164
file_put_contents($targetFilePath, $fileContent);
164165
print "File {$fileUrl} has been downloaded successfully\r\n";
165-
}
166+
}
167+
168+
function downloadFileAsStream(ClientRuntimeContext $ctx, $fileUrl, $targetFilePath) {
169+
$fileUrl = rawurlencode($fileUrl);
170+
171+
$fp = fopen($targetFilePath, 'w+');
172+
$url = $ctx->getServiceRootUrl() . "web/getfilebyserverrelativeurl('$fileUrl')/\$value";
173+
$options = new \Office365\PHP\Client\Runtime\Utilities\RequestOptions($url);
174+
$options->StreamHandle = $fp;
175+
$ctx->executeQueryDirect($options);
176+
fclose($fp);
177+
178+
print "File {$fileUrl} has been downloaded successfully\r\n";
179+
}

src/Runtime/Utilities/RequestOptions.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function __construct($url, $headers = array(), $data = null, $methodType
2727
$this->UserCredentials = null;
2828
$this->Verbose = false;
2929
$this->SSLVersion = null;
30+
$this->StreamHandle = null;
3031
}
3132

3233
public function toArray()
@@ -42,10 +43,10 @@ public function toArray()
4243
'Verbose' => $this->Verbose,
4344
'UserCredentials' => $this->UserCredentials,
4445
'SSLVersion' => $this->SSLVersion,
46+
'StreamHandle' => $this->StreamHandle,
4547
];
4648
}
4749

48-
4950
public function addCustomHeader($name, $value)
5051
{
5152
if (is_null($this->Headers))
@@ -127,4 +128,10 @@ function ($k, $v) {
127128
*/
128129
public $SSLVersion;
129130

131+
132+
/**
133+
* @var resource
134+
*/
135+
public $StreamHandle;
136+
130137
}

src/Runtime/Utilities/Requests.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ private static function init(RequestOptions $options)
109109
//set Post Body
110110
if(isset($options->Data))
111111
curl_setopt($ch, CURLOPT_POSTFIELDS, $options->Data);
112+
if(is_resource($options->StreamHandle))
113+
curl_setopt($ch, CURLOPT_FILE, $options->StreamHandle);
112114
$options->addCustomHeader("content-length",strlen($options->Data));
113115
//custom HTTP headers
114116
if($options->Headers)

0 commit comments

Comments
 (0)