私はPHPで 'deny all'コマンドを使って保護されているバックアップディレクトリの内容をリストアップしようとしています。 htaccessファイル。PHPスクリプトは、 'deny all'(Via .htaccess)ディレクトリにアクセスします。
これはWordPressのバックアッププラグインである理由は管理者だけが利用でき、私は単純なダッシュボードウィジェットを使用してオンラインからバックアップをダウンロードできるようにしたいと考えています。
私が使用しているコードは、htaccessファイルのために403エラーが発生したときに見つかります。
//define the directory (this is where the backup plugin store the .zip files)
$directory = site_url() . "/wp-content/backups/";
//display the generated directory for testing
echo '<b>Scanning: </b>' . $directory . '</br></br>';
//display a link to a test.zip I know exists for testing
echo '<b>Manual Link: </b> <a href="' . $directory . 'test.zip" target="_blank">test.zip</a></br></br>';
//get all files in the directory with a .zip extension.
$files = glob($directory . "*.zip");
//print each file name as a download link
foreach($files as $file){
echo '<a href="' . $file . '">' . $file . '</a> </br>';
}
ご協力いただければ助かります。
ありがとう、 アンディ。コード上の
更新することをグロブが正しく
//Define the backup folder location
$backup_location = "wp-content/backups/";
//Set the file directory for glob
$directory = $_SERVER['DOCUMENT_ROOT'] . $backup_location;
//Prints the directory for testing purposes
echo '<b>Scanning: </b>' . $directory . '</br></br>';
//Filter the discovered files
$files = glob($directory . "*.*");
//Echo the filtered files
foreach($files as $file){
echo '<a href="' . site_url() . '/' . $backup_location . basename($file) . '">' . basename($file) . '</a> </br>';
}
site_url()は何を返しますか? –
サイトURL(WPバックエンドで定義されています)を返すWordPress変数です。他のコメントから、グロブはURLで動作しないようですが。 –
はい、そうです.GlobはHTTP経由では動作しません。代わりにローカルパスを使用してください。 htaccessはファイルシステム経由のアクセスを制限しないので、問題はないはずです。 –