【问题标题】:Upload large files to WebDAV with resume support支持简历上传大文件到 WebDAV
【发布时间】:2016-01-02 07:37:20
【问题描述】:

我想通过 WebDAV API 将大文件上传到 ownCloud。

我使用此代码来执行此操作:

<?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";
}
?>

但是当连接丢失时,此脚本无法继续上传文件。

是否可以使用 WebDAV 恢复文件上传?

谢谢

【问题讨论】:

    标签: php curl libcurl webdav resume-upload


    【解决方案1】:

    使用CURLOPT_RESUME_FROM_LARGE option

    要么将其设置为开始简历的位置。或者使用-1 让 curl 在部分上传的文件末尾自动恢复。

    请注意,这只会影响远程端。您还需要寻找指向相同位置的本地文件读取指针(使用fseek)。所以,如果你想在部分上传的文件末尾恢复,你需要先查询它的大小,知道在哪里寻找本地文件读取指针。
    为此请参阅Remote file size without downloading file

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-24
      • 2010-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多