2015-10-05 95 views
0

我想使用WebDAV API將大文件上傳到ownCloud。使用簡歷支持將大文件上傳到WebDAV

我用這個代碼來做到這一點:

<?php 
$url = "http://user:[email protected]/remote.php/webdav/test.mp4"; 
$localfile = "test.mp4"; 
$fp = fopen ($localfile, "r"); 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_VERBOSE, 1); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_PUT, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_INFILE, $fp); 
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile)); 
$http_result = curl_exec($ch); 
$error = curl_error($ch); 
$http_code = curl_getinfo($ch ,CURLINFO_HTTP_CODE); 
curl_close($ch); 
fclose($fp); 
print $http_code; 
print "<br /><br />$http_result"; 
if ($error) { 
    print "<br /><br />$error"; 
} 
?> 

但是,當連接丟失,這個腳本不能恢復上傳文件。

是否有可能使用WebDAV恢復文件上傳?

謝謝

回答

0

使用CURLOPT_RESUME_FROM_LARGE option

要麼將​​其設置爲從其開始恢復的位置。或者使用-1在部分上傳的文件末尾自動恢復捲曲。

請注意,這僅影響遠程端。您還需要查找本地文件讀取指針到相同的位置(使用fseek)。因此,如果您想要在部分上傳的文件末尾恢復,則需要首先查詢其大小,以知道在哪裏查找本地文件讀取指針。
對於此參見PHP: Remote file size without downloading file