使用 PHP 对上传进行卷曲分块


Curl chunked uploads with PHP

我编写了一个PHP脚本,该脚本使用CURL将大文件从一个Windows服务器传输到另一个Windows服务器。两者都运行 IIS,它对文件上传有 2GB 的限制。我的进程非常适合小于 2GB 的文件。但是,对于 2GB>的文件,它会失败。

听说 CURL 可能能够以块的形式发送文件,这可能会解决我的问题。但是,我找不到任何关于如何做到这一点的好例子。我目前的工作代码发布在下面。有谁知道如何修改它以块(即 100MB 块)发送我的文件?

$postVars = array("file1" => $fileContents1,
                  "file2" => $fileContents2,
                  "outputPath" => $outputPath);
// Initializing curl
$ch = curl_init();
// Configuring curl options
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_VERBOSE, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_BUFFERSIZE, '64000');
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_SSLVERSION, '3');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: multipart/form-data'));
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_POSTFIELDS,$postVars);
echo "Sending files...'n";
curl_setopt($ch, CURLOPT_TIMEOUT, 9999);
if(curl_exec($ch) === false)
{
    echo 'Curl error: ' . curl_error($ch);
}
else
{
    echo 'Operation completed without any errors';
}
$info = curl_getinfo($ch);
print_r($info);
curl_close($ch);

plupload是一个JavaScript/php库,它非常易于使用,并允许对所需大小进行分块。

不过它使用HTML5。 I found only the way to uploading a large file is PlUpload Library并制作文件管理器应用程序。希望它也能帮助你。