我有我要下载的文件的链接,但文件保存时带有一个奇怪的名字,如" 450033" 没有任何文件扩展名。
唯一对我有用的代码(部分)就是这个
<?php
$file_path = "url to file";
ob_start();
header("Content-Type: application/zip");
header('Content-Length: '.remotefilesize($file_path) );
header("Content-disposition: attachment; filename=thefile.zip");
$chunksize = 128 * 1024; // how many bytes per chunk (128 KB)
$size = filesize($file_path);
if ($size > $chunksize){
$handle = fopen($file_path, 'rb');
$buffer = '';
while (!feof($handle)) {
buffer = fread($handle, $chunksize);
echo $buffer;
flush();
sleep(1);
}
fclose($handle);
}else{
readfile($file_path);
}
?>
上面的代码下载文件但没有显示任何进度条,页面实际上只是一直加载,直到下载文件。 有没有重命名文件并显示进度条呢?