21,886
社区成员
发帖
与我相关
我的任务
分享
$id = isset($_REQUEST['id']) ? trim($_REQUEST['id']) : 0;
$file_path = 'http://www.********.com/file/';
$file_name = 'aaa_'.$id.'.rar';
if (file_exists($file_path . $file_name)){
header( "Pragma: public" );
header( "Expires: 0" );
header( 'Content-Encoding: none' );
header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
header( "Cache-Control: public" );
header( "Content-type: application/octet-stream\n" );
header( "Content-Description: File Transfer" );
header( 'Content-Disposition: attachment; filename=' . $file_name );
header( "Content-Transfer-Encoding: binary" );
header( 'Content-Length: ' . filesize ( $file_path . $file_name ) );
readfile ( $file_path . $file_name );
} else {
echo '<script>alert("获取下载地址出错!")</script>';
echo '<script>location.replace("download.php");</script>';
exit;
}
if (file_exists($file_path . $file_name)){
echo '<script>location.replace("'.$file_path . $file_name.'");</script>';
exit;
} else {
echo '<script>alert("获取下载地址出错!")</script>';
echo '<script>location.replace("download.php");</script>';
exit;
}
<a href="http://www.******.com/file/aaa_1.rar">下载文件</a>