我的網站使用此代碼下載一個文件:頭的ReadFile
$flv = **filename**
$ch = curl_init($flv);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //not necessary unless the file redirects (like the PHP example we're using here)
$data = curl_exec($ch);
curl_close($ch);
if ($data === false) {
echo 'cURL failed';
exit;
}
$contentLength = 'unknown';
if (preg_match('/Content-Length: (\d+)/', $data, $matches)) {
$contentLength = (int)$matches[1];
}
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($flv));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . $contentLength);
ob_clean();
flush();
readfile($flv);
代碼工作,但是,直到完成下載的鏈接一個頁面都bloqued,等待下載完成!
我該怎麼辦?
你嘗試刪除? ob_clean();和flush(); – 2009-08-06 14:05:47
是的,但沒有結果... – Pedro 2009-08-06 14:06:55
「echo readfile($ flv);」 ? – 2009-08-06 14:10:00