【发布时间】:2017-12-24 06:12:23
【问题描述】:
我想使用 guzzle 将文件分块上传到 URL 端点。
我应该能够提供 Content-Range 和 Content-Length 标头。
使用 php 我知道我可以使用拆分
define('CHUNK_SIZE', 1024*1024); // Size (in bytes) of chunk
function readfile_chunked($filename, $retbytes = TRUE) {
$buffer = '';
$cnt = 0;
$handle = fopen($filename, 'rb');
if ($handle === false) {
return false;
}
while (!feof($handle)) {
$buffer = fread($handle, CHUNK_SIZE);
echo $buffer;
ob_flush();
flush();
if ($retbytes) {
$cnt += strlen($buffer);
}
}
$status = fclose($handle);
if ($retbytes && $status) {
return $cnt; // return num. bytes delivered like readfile() does.
}
return $status;
}
如果可能的话,如何使用 guzzle 流来实现以块的形式发送文件?
【问题讨论】: