我有这段代码:
if (isset($_GET['file']) && isset($_GET['name']))
{
$ch = curl_init($file);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
$data = curl_exec($ch);
curl_close($ch);
if (preg_match('/Content-Length: (\d+)/', $data, $matches))
{
// Contains file size in bytes
$contentLength = (int)$matches[1];
}
header("Content-type: application/x-file-to-save");
header("Content-Disposition: attachment; filename=".$_REQUEST['name']);
header('Content-Length: ' . $contentLength);
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
header('Connection: Keep-Alive');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0', false);
header('Cache-Control: private', false);
readfile($file);
}
问题在于$file位于不同的服务器。如何启用此下载的续传呢?谢谢!
curl
重写您的解决方案,而不是使用readfile()
。完成后,请返回并修改您的问题。 - zerkms