English 中文(简体)
下载时的mod_rewriter - 使查找文件显得可疑
原标题:mod_rewrite to download - makes suspicous looking file

我决定尝试使用 mod_ rewrite 来隐藏文件的位置, 用户可以下载 。

因此他们点击一个链接, 指向“ / download/ some_ file/ ”, 取而代之的是“/ downloads/ some_ file.zip ” 。

如下所述,已执行:

RewriteRule ^download/([^/.]+)/?$ downloads/$1.zip [L]

除了当下载进度显示时, 我得到了一个文件“ 下载”, 没有扩展名, 看上去可疑, 用户可能不知道他们应该解开它。 是否有一种方法可以这样做, 它看起来像一个实际的文件? 或者有更好的方法我应该这样做吗?

以提供隐藏文件位置的某种背景/理由。 这是用于一个可以免费下载音乐的乐队, 只要用户在邮件列表上签名 。

我不需要在.hhtaccess范围内做这个

最佳回答
问题回答

所以我认为我只能使用.hhtaccess 设置什么信头

所以我用php解决了这个问题

I initially copied a download php script found here: How to rewrite and set headers at the same time in Apache

但我的文件大小太大了 所以这不起作用

」 http://teddy.fr/blog/how-serve- big-files- through-php http://teddy.fr/blog/how-serve- big-files- through-php

因此,我的完全解决方案如下:

首先发送下载脚本的请求 :

RewriteRule ^download/([^/.]+)/?$ downloads/download.php?download=$1 [L]

然后获得完整的文件名, 设置信头, 并按块为它服务 :

<?php
if ($_GET[ download ]){
  $file = $_SERVER[ DOCUMENT_ROOT ]. media/downloads/  . $_GET[ download ] .  .zip ;
}

define( CHUNK_SIZE , 1024*1024); // Size (in bytes) of tiles chunk

// Read a file and display its content chunk by chunk
function readfile_chunked($filename, $retbytes = TRUE) {
    $buffer =   ;
    $cnt =0;
    // $handle = fopen($filename,  rb );
    $handle = fopen($filename,  rb );
    if ($handle === false) {
      return false;
    }

    while (!feof($handle)) {
        $buffer = fread($handle, CHUNK_SIZE);
        echo $buffer;
        ob_flush();
        flush();
        if ($retbytes) {
            $cnt += strlen($buffer);
        }   
    }
    $status = fclose($handle);
    if ($retbytes && $status) {
        return $cnt; // return num. bytes delivered like readfile() does.
    }
    return $status;
}

$save_as_name = basename($file);   
header( Cache-Control: must-revalidate, post-check=0, pre-check=0 );
header( Pragma: no-cache );
header("Content-Type: application/zip");
header("Content-Disposition: disposition-type=attachment; filename="$save_as_name"");

readfile_chunked($file); 
?>




相关问题
How to upload and download file from a server using C#

I am developing a webpage in that the user can download their Resume for Edit. So I have a link to download the article. I use the following code for download. DataTable dt = user.getUserDetails(2); ...

Detecting PDF Download

I have recently added functionality for generating pdf reports to a web application. However the reports can be quite large and take some time to show the pdf download dialog. I want to show a spinner ...

Writing file to users giving sporadic error in IE

I have a very interesting issue with only specific IE implementations. I have an ASPX page that is used to write files down to the user, as part of the process the page uses the following code to ...

PHP - List of Excel files to download from Intranet Site?

I have a intranet site running PHP 5 that needs to list a folder containing only Excel files. Ideally the user needs to be able to input some search criteria (ie date) and the files would be filtered ...

Determine total size of SVN directory/trunk

Is there a way to count/calculate the total size of a svn directory if you were to checkout a revision? I have limited internet downloads so I need to know how big something is before I go and ...

Scala and html: download an image (*.jpg, etc) to Hard drive

I ve got a Scala program that downloads and parses html. I got the links to the image files form the html, Now I need to transfer those images to my hard drive. I m wondering what the best Scala ...

Downloading file with wxHTTP?

Im really stumped. Im using the wxHTTP class in wxWidgets to try and download two files. The first request succeeds but the second one fails when wxHTTP->GetInputStream is called. Between downloads, ...

热门标签