Upload large files to WebDAV with resume support

假如想象 提交于 2019-12-10 12:04:14

问题


I want to upload large files to ownCloud with WebDAV API.

I use this code to do this:

<?php
$url = "http://user:password@owncloud.local/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";
}
?>

But when connection lost, this script cannot resume uploading file.

Is it possible to resume file upload with WebDAV?

Thanks


回答1:


Use the CURLOPT_RESUME_FROM_LARGE option.

Either set it to a position to start the resume from. Or use the -1 to make the curl automatically resume at the end of the partially uploaded file.

Note that this affects the remote side only. You also need to seek the local file read pointer to the same position (using the fseek). So, if you want to resume at the end of the partially uploaded file, you need to query its size first, to know where to seek the local file read pointer to.
For that see Remote file size without downloading file.



来源:https://stackoverflow.com/questions/32952124/upload-large-files-to-webdav-with-resume-support

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!