通过恢复支持将大文件上传到WebDAV [英] Upload large files to WebDAV with resume support

查看:229
本文介绍了通过恢复支持将大文件上传到WebDAV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用WebDAV API将大文件上传到ownCloud.

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.

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

Is it possible to resume file upload with WebDAV?

谢谢

推荐答案

使用 CURLOPT_RESUME_FROM_LARGE选项.

将其设置为开始简历的位置.或使用-1使卷曲在部分上传的文件的末尾自动恢复.

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.

请注意,这仅影响远程端.您还需要查找指向相同位置的本地文件读取指针(使用 fseek ).因此,如果要在部分上传的文件的末尾继续,则需要首先查询其大小,以了解在何处查找本地文件的读取指针.
为此,请参见远程文件大小而不下载文件.

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.

这篇关于通过恢复支持将大文件上传到WebDAV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆