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