0
私はダウンロードPHPスクリプトで作業していますが、ファイルパスは可変です。get()を使用してファイルのファイルパスを取得できますか?または私は何か他のことをすることができます。 ご協力いただきありがとうございます。ダウンロードスクリプトに変数ファイルのパスを追加する方法に関するアドバイス
PHPスクリプト -
if (isset($_GET['file']) && basename($_GET['file']) == $_GET['file']) {
$filename = $_GET['file'];
} else {
$filename = NULL;
}
$err = '<p>Sorry, the file you are requesting is unavailable.</p>';
if (!$filename) {
// if variable $filename is NULL or false display the message
echo $err;
} else {
// path
$path = './'.$filename;
// check that file exists and is readable
if (file_exists($path) && is_readable($path)) {
// get the file size and send the http headers
$size = filesize($path);
header('Content-Type: application/octet-stream');
header('Content-Length: '.$size);
header('Content-Disposition: attachment; filename='.$filename);
header('Content-Transfer-Encoding: binary');
// open the file in binary read-only mode
// display the error message if file can't be opened
$file = @ fopen($path, 'rb');
if ($file) {
// stream the file and exit the script when complete
fpassthru($file);
exit;
} else {
echo $err;
}
} else {
echo $err;
}
}
はい、 '$ _GET'を使ってファイル名を取得することができます。既に行っているようです。それでは、質問/問題は何ですか? – Progman
これは安全ですか?私はそれをしたくないので、私が避けようとしているファイルであるエンドユーザーにファイルのパスを伝えることが明らかになります。それで、他にも安全な方法がありますか? –
@ProgmanのURLはこのようになりますsomesite.com/download.php?download_file=test.doc&path=/t1/a/test2/ –