【问题标题】:How Can I use .htaccess to return another file to the client?如何使用 .htaccess 将另一个文件返回给客户端?
【发布时间】:2011-09-20 12:47:21
【问题描述】:

如果有人请求“filename.rar”,我想返回“download.php?file=filename”的内容

【问题讨论】:

标签: php .htaccess download


【解决方案1】:
RewriteEngine on
RewriteRule (.*)\.rar download.php?file=$1.rar

【讨论】:

  • 谢谢。你能告诉我“RewriteEngine on”是什么意思吗?
【解决方案2】:

这会将您的服务器变成一扇敞开的大门,任何人都可以获取他们想要的任何文件,但是......它可以满足您的需求。

<?php
    readfile($_REQUEST['file']);

享受...

【讨论】:

    【解决方案3】:
    if(isset($_GET[file]))
    
     header("Location: PATH TO FILE");
    

    $filename = 'FILENAME';
    $file = 'PATH TO FILE';
    
    
    header("Content-Disposition:  inline; filename=".$filename);
    header("Content-Type: application/octet-stream");
    header("Content-Length: ".filesize($file));
    header("Pragma: no-cache");
    header("Expires: 0");
    $fp=fopen($file,"r");
    print fread($fp,filesize($file));
    fclose($fp);
    exit();
    

    【讨论】:

    • 您没有阅读问题。他想把file.rar转成download.php?file=file.rar
    猜你喜欢
    • 2020-11-22
    • 2020-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-13
    • 1970-01-01
    相关资源
    最近更新 更多