Я пытаюсь получить сценарий php для отображения содержимого каталога резервной копии, защищенного с помощью команды 'deny all', в файле .htaccess.
Причиной этого является плагин резервного копирования.Поскольку WordPress доступен только для администраторов, и я хотел бы дать пользователю с более низким рейтингом возможность загружать свои резервные копии из Интернета (с помощью простого виджета панели инструментов).
Вы можете найти код, который я использую нижеи он отключается при обнаружении ошибки 403. из-за файла htaccess.
//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>';
}
Любая помощь, которую вы можете предоставить, будет наиболее полезной.
Спасибо, Энди.
Обновление кода, чтобы glob работал правильно
//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>';
}