0

ファイルのダウンロード数のカウントに問題があります。ダウンロード ファイルへのリンクが http:// your.site.domain/download.php?file=filename.exe&customer=ABC_423 のようになっていれば問題ありません。ただし、私の顧客は次のようなリンクから統計をカウントしたいと考えています: http:// your.site.domain/downloadsfolder/ABC_423/filename.exe また、他のサイトでそのリンクをホットリンクする必要があります。

.htaccess ファイルに解決策があると思いますが、適切なリダイレクトを行う方法がわかりません。

私のPHPスクリプトは次のようになります。

session_start();
define('SERVER_NAME', 'www.siteaddress.domain');
define('DOWNLOAD_PATH', 'http:// siteaddress.domain/versions/download');
define('DOWNLOAD_FILE', 'Setup.exe');

$filename = DOWNLOAD_PATH . '/' . $_GET['customer'] . '/' . DOWNLOAD_FILE;

$headers = get_headers($filename);

if ($headers[0] == 'HTTP/1.1 200 OK'){
  // file exists, begin download procedure
  if(isset($_GET['customer'])){
    // begin update statistics
    // mysql query to update specified row
  }
  // headers for downloading file
  header("Content-Type: application/force-download");
  header('Content-Type: application/x-unknown');
  header("Content-Type: application/octet-stream");
  //header("Content-Type: application/download"); // not sure if needed
  header("Content-Disposition: attachment; filename=".basename($filename).";");
  header("Accept-Ranges: bytes");
  header("Content-Transfer-Encoding: binary");
  header("Content-Length: ".remote_filesize(SERVER_NAME, $filename));
  ob_clean();
  flush();
  readfile($filename);
  exit;
}else{
  echo 'File not found';
  exit;
}

4

1 に答える 1

2

これは で簡単RewriteRuleです.htaccess。このようなもの:

RewriteEngine On
RewriteRule   ^/downloadsfolder/(.*)/(.*)     /download.php?file=$2&customer=$1    [L]

ランダムな文字列がどのように検出され、変換された URL で検出された各項目で(.*)使用さ$1れるかを観察します。$2

それが役に立ったことを願っています!

于 2013-03-01T14:51:24.863 に答える