我想獲得一個PHP腳本來列出一個備份目錄的內容使用'拒絕所有'命令在一個。 htaccess文件。PHP腳本訪問一個目錄,否則'拒絕所有'(通過.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>';
}
你可以提供的任何幫助將是最有幫助的。
謝謝, Andy。在代碼
更新,使水珠正常工作
//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()返回什麼? –
這是一個WordPress變量,返回站點URL(在WP後端定義)。雖然從其他評論看來,glob不能通過url的工作。 –
是的,這是真的,glob不通過HTTP工作。改用本地路徑。 htaccess不限制通過文件系統訪問,所以你不應該有任何問題。 –