2

誰もが http 経由でアクセスできるフォルダーである「public_html」の外部からユーザーにファイルをアップロードするのに問題があります。元。www.website.com/ / の後のすべてが public_html です。私が何を指しているのか、皆さんはご存知だと思います。

したがって、(サーバーの観点から) /images/protected/ からファイル (sample.pdf) を読み取る必要があるこのスクリプトがありますが、PHP はファイルを見つけられません。私はこれを間違っていますか?

<?php
$file = '/images/protected/sample.pdf';

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
} else {
    echo "404 - FILE NOT FOUND!<br />\n";
    echo "File: $file";
}
?>

このスクリプトを実行するたび404 - FILE NOT FOUND!<br />\nに、ファイルのダウンロードではなく、.

4

2 に答える 2

4

絶対システム パスを指定する必要があります。/images/...現在、ではなく でファイルをリクエストしています/var/www/hosts/whateverdomain/images/...

$file = $_SERVER['DOCUMENT_ROOT'].'/images/protected/sample.pdf';

ファイルが本当に にある場合は/images/protected/、そのファイルを読み取るための十分な権限があることを確認してください。

于 2011-10-24T20:31:56.377 に答える
0

私は共有ホスティングを使用していることが判明したため、私のウェブサイトの正しい「ルート」パスは /home/me/ でした

于 2011-10-28T15:11:27.240 に答える