私は 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);