0
我怎么能用htaccess来做这件事?只为php用户下载文件htaccess
if (url has not parameter ?down=true)
redirect back
else
do noting
end if
例如
example.com/upload/file.pdf //它不能立即下载该文件
example.com/upload/file.pdf?down=true //它必须下载文件
请帮我:)
这是我的htaccess文件
RewriteEngine on
RewriteRule ^upload/file/(.*) http\:\/\/www\.example\.org\/down.php?file=$1 [L]
这是down.php页
<?php
session_start();
if(isset($_SESSION["user_id"])){
if(isset($_GET["file"])) $file = mysql_escape_string($_GET["file"]);
$file = "http://www.example.org/upload/file/".$file;
$file = preg_replace("/ /", "%20", $file);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
//header('Content-Length: ' . filesize($file));
readfile($file);
exit;
}else{
header('Location:login.php');
}
exit();
感谢您的回复,但你可以写完整的条件,我 因为我失败了 – 2015-02-08 14:25:46