douyinlai2169 2015-10-05 15:20
浏览 397
已采纳

通过简历支持将大文件上传到WebDAV

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条回答 默认 最新

  • duanjitong7226 2015-10-06 06:36
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵