download.php?id=1 点击之后下载文件$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;
}
这样可以使用浏览器另存为的方式下载,但如果是迅雷下载时显示下载文件为download.php这是怎么回事?如果是不弹出迅雷的下载窗口直接使用浏览器自带的下载方式改怎么写呢?有没有什么方法把文件存放的地址直接导向到迅雷的url下载地址?还有其它的下载文件的代码写法吗?
$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;
}
这样可以使用浏览器另存为的方式下载,但如果是迅雷下载时显示下载文件为download.php这是怎么回事?如果是不弹出迅雷的下载窗口直接使用浏览器自带的下载方式改怎么写呢?有没有什么方法把文件存放的地址直接导向到迅雷的url下载地址?还有其它的下载文件的代码写法吗?
在onClick中检查登录。
请问怎么使用js检测用户登录状态,程序里面是使用session,js里怎么判断?
echo '<script>location.replace("'.$file_path . $file_name.'");</script>';
exit;
} else {
echo '<script>alert("获取下载地址出错!")</script>';
echo '<script>location.replace("download.php");</script>';
exit;
}
echo 'location.replace("'.$file_path . $file_name.'");';
exit;
} else {
echo 'alert("获取下载地址出错!");';
echo 'location.replace("download.php");';
exit;
}下载时用ajax请求,并在js里eval返回结果
header("Content-length:".filesize($filename));
header( 'Content-Disposition: attachment; filename=' . $file_name );}