【发布时间】:2018-02-01 22:01:36
【问题描述】:
我似乎无法使用 curl 恢复 FTP 上传。它总是将完整的本地文件附加到部分上传的远程文件,导致远程文件比本地文件大。
我想知道我是否错过了某个选项,或者curl_multi 是否与此有关?
$resume = true
$filesize 是远程文件的当前大小,以字节为单位,使用单独的 curl ftp 请求获取。
我尝试过开启和关闭CURLOPT_FTPAPPEND 选项。
任何帮助都会很棒,因为我正在努力解决这个问题 :)
...
$ch[$i] = curl_init();
$file = fopen($local_file, 'rb');
if ($resume)
{
curl_setopt($ch[$i], CURLOPT_RESUME_FROM, $filesize);
// move file position forward to resume
fseek($file, $filesize);
}
curl_setopt($ch[$i], CURLOPT_URL, $remote_file);
curl_setopt($ch[$i], CURLOPT_PROTOCOLS, CURLPROTO_SFTP);
curl_setopt($ch[$i], CURLOPT_USERPWD, "{$ftp['user']}:{$ftp['pass']}");
curl_setopt($ch[$i], CURLOPT_UPLOAD, true);
curl_setopt($ch[$i], CURLOPT_HEADER, false);
curl_setopt($ch[$i], CURLOPT_INFILE, $file);
curl_setopt($ch[$i], CURLOPT_INFILESIZE, filesize($local_file));
curl_multi_add_handle($mh, $ch[$i]);
...
更新
由于几个小时的谷歌搜索没有帮助,我想出了一个简单的解决方法。
关于使用 curl 恢复上传的帖子不多,所以我希望这可以帮助其他人节省时间。
使用fseek() 只是一行,但通常情况下是这样的;)
【问题讨论】:
-
我找到了解决方法,但有人能告诉我为什么它不起作用吗?谢谢
标签: php curl curl-multi