0

私は Martin Barker のコード/回答 ( PDF と DOC を保護するための PHP ) をほぼそのまま使用しています。唯一の違いは、保護しているファイルが public_html フォルダーの上のユーザー フォルダーにあることです。

フォルダ構造

/users/websupport
/public_html

ダウンロードするファイルは次の場所にあります。

/users/websupport/FileToDownload.pdf

download.php ファイルは次の場所にあります。

/public_html/download.php

しかし、Firefox は、Firefox が download.php でファイルを見つけることができないと言っています。

ftp経由でファイルがあることを確認しました。

ファイルを webroot の外に配置する場合、サイト .htaccess に何かを追加する必要がありますか? これのどこが間違っているのかわかりません。以下はdownload.php内のコードです

//check users is loged in and valid for download if not redirect them out
// YOU NEED TO ADD CODE HERE FOR THAT CHECK
// array of support file types for download script and there mimetype
$mimeTypes = array(
    'doc' => 'application/msword',
    'pdf' => 'application/pdf',
);
// set the file here (best of using a $_GET[])
$file = "../users/websupport/2011cv.pdf";

// gets the extension of the file to be loaded for searching array above
$ext = explode('.', $file);
$ext = end($ext);

// gets the file name to send to the browser to force download of file
$fileName = explode("/", $file);
$fileName = end($fileName);

// opens the file for reading and sends headers to browser
$fp = fopen($file,"r") ;
header("Content-Type: ".$mimeTypes[$ext]);
header('Content-Disposition: attachment; filename="'.$fileName.'"');

// reads file and send the raw code to browser
while (! feof($fp)) {
    $buff = fread($fp,4096);
    echo $buff;
}
// closes file after whe have finished reading it
fclose($fp);
4

2 に答える 2

0

PHPスクリプトを実行するユーザーがそのディレクトリへの読み取りアクセス権を持っていることを確認してください。

ほとんどの debian 派生物の apache に埋め込まれた php では、ユーザーは「www-data」になります。

于 2012-06-25T15:52:04.770 に答える