// 方法一
$file='alonesky/index.php';
echo download($file);
function download($file){
if(empty($file)||!is_file($file)||!file_exists($file)){
echo '404';
exit;
}
header('Content-Type:application/octet-stream');
$fileName=basename($file);
header('Content-Disposition:attachment;filename="'.$fileName.'"');
$buffer='';
$cnt=0;
$handle=fopen($file,'rb');
if($handle===false){
return false;
}
while(!feof($handle)){
$buffer=fread($handle,1024*1024);
echo $buffer;
ob_flush();
flush();
$cnt+=strlen($buffer);
}
$status=fclose($handle);
if($status){
return $cnt;
}
return $status;
}
// 方法二
$filename="alonesky/index.php";
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=".$filename);
readfile($filename);exit;