рекурсивное копирование каталогов, манипулирование путем к файлу - PullRequest
0 голосов
/ 04 марта 2020

Я пытаюсь создать функцию, с помощью которой пользователь переходит на страницу, являющуюся частью плагина Wordpress, проверяет флажки, для каких частей папки wp-content сделать копию, а затем копирует эти каталоги в форму. однако, я застрял, получая возможность выбирать, какие папки создавать резервные копии, не путая путь к файлу при рекурсивном копировании частей папки в место назначения, код ниже предназначен для обработчика формы (реализован только параметр тем из формы ) и функция для копирования файлов, это срабатывает, когда форма отправляет флажки. нижеприведенный фрагмент является текущим выходом.

add_action('admin_post_submit-content-form', 'sisb_content_backup_handler'); // If the user is logged in
add_action('admin_post_nopriv_submit-content-form', 'redirect_home'); // If the user in not logged in


function sisb_content_backup_handler(){
  if(isset($_POST['themes'])){
    sisb_content_dir_copy('themes');
  }
}

function sisb_content_dir_copy($currentbak) {
    $url = $_SERVER['DOCUMENT_ROOT'];
    $src =  $url. "/wp-content/".$currentbak;
    echo $src;
    // open the source directory
    $dir = opendir($src);
    $dst = $url."/wp-content/plugins/WP-SISB/contentbackups/".$currentbak;
    //echo '</br>'.$dst;
    // Make the destination directory if not exist
    mkdir($dst);

    // Loop through the files in source directory
    while( $file = readdir($dir) ) {

        if (( $file != '.' ) && ( $file != '..' )) {
            if ( is_dir($src . '/' . $file) )
            {

                // Recursively calling custom copy function
                // for sub directory
                sisb_content_dir_copy($src . '/' . $file, $dst . '/' . $file);

            }
            else {
                copy($src . '/' . $file, $dst . '/' . $file);
            }
        }
    }

    closedir($dir);
}

/srv/www/sisb/public_html/wp-content/themes
Warning: mkdir(): File exists in /srv/www/sisb/public_html/wp-content/plugins/WP-SISB/wp-sisb.php on line 247
/srv/www/sisb/public_html/wp-content//srv/www/sisb/public_html/wp-content/themes/twentynineteen
Warning: opendir(/srv/www/sisb/public_html/wp-content//srv/www/sisb/public_html/wp-content/themes/twentynineteen): failed to open dir: No such file or directory in /srv/www/sisb/public_html/wp-content/plugins/WP-SISB/wp-sisb.php on line 243

Warning: mkdir(): No such file or directory in /srv/www/sisb/public_html/wp-content/plugins/WP-SISB/wp-sisb.php on line 247

Warning: readdir() expects parameter 1 to be resource, boolean given in /srv/www/sisb/public_html/wp-content/plugins/WP-SISB/wp-sisb.php on line 250

Warning: closedir() expects parameter 1 to be resource, boolean given in /srv/www/sisb/public_html/wp-content/plugins/WP-SISB/wp-sisb.php on line 267
/srv/www/sisb/public_html/wp-content//srv/www/sisb/public_html/wp-content/themes/twentyseventeen
Warning: opendir(/srv/www/sisb/public_html/wp-content//srv/www/sisb/public_html/wp-content/themes/twentyseventeen): failed to open dir: No such file or directory in /srv/www/sisb/public_html/wp-content/plugins/WP-SISB/wp-sisb.php on line 243

Warning: mkdir(): No such file or directory in /srv/www/sisb/public_html/wp-content/plugins/WP-SISB/wp-sisb.php on line 247

Warning: readdir() expects parameter 1 to be resource, boolean given in /srv/www/sisb/public_html/wp-content/plugins/WP-SISB/wp-sisb.php on line 250

Warning: closedir() expects parameter 1 to be resource, boolean given in /srv/www/sisb/public_html/wp-content/plugins/WP-SISB/wp-sisb.php on line 267
/srv/www/sisb/public_html/wp-content//srv/www/sisb/public_html/wp-content/themes/twentysixteen
Warning: opendir(/srv/www/sisb/public_html/wp-content//srv/www/sisb/public_html/wp-content/themes/twentysixteen): failed to open dir: No such file or directory in /srv/www/sisb/public_html/wp-content/plugins/WP-SISB/wp-sisb.php on line 243

Warning: mkdir(): No such file or directory in /srv/www/sisb/public_html/wp-content/plugins/WP-SISB/wp-sisb.php on line 247

Warning: readdir() expects parameter 1 to be resource, boolean given in /srv/www/sisb/public_html/wp-content/plugins/WP-SISB/wp-sisb.php on line 250

Warning: closedir() expects parameter 1 to be resource, boolean given in /srv/www/sisb/public_html/wp-content/plugins/WP-SISB/wp-sisb.php on line 267
/srv/www/sisb/public_html/wp-content//srv/www/sisb/public_html/wp-content/themes/twentytwenty
Warning: opendir(/srv/www/sisb/public_html/wp-content//srv/www/sisb/public_html/wp-content/themes/twentytwenty): failed to open dir: No such file or directory in /srv/www/sisb/public_html/wp-content/plugins/WP-SISB/wp-sisb.php on line 243

Warning: mkdir(): No such file or directory in /srv/www/sisb/public_html/wp-content/plugins/WP-SISB/wp-sisb.php on line 247

Warning: readdir() expects parameter 1 to be resource, boolean given in /srv/www/sisb/public_html/wp-content/plugins/WP-SISB/wp-sisb.php on line 250

Warning: closedir() expects parameter 1 to be resource, boolean given in /srv/www/sisb/public_html/wp-content/plugins/WP-SISB/wp-sisb.php on line 267
/srv/www/sisb/public_html/wp-content//srv/www/sisb/public_html/wp-content/themes/virtue
Warning: opendir(/srv/www/sisb/public_html/wp-content//srv/www/sisb/public_html/wp-content/themes/virtue): failed to open dir: No such file or directory in /srv/www/sisb/public_html/wp-content/plugins/WP-SISB/wp-sisb.php on line 243

Warning: mkdir(): No such file or directory in /srv/www/sisb/public_html/wp-content/plugins/WP-SISB/wp-sisb.php on line 247

Warning: readdir() expects parameter 1 to be resource, boolean given in /srv/www/sisb/public_html/wp-content/plugins/WP-SISB/wp-sisb.php on line 250

Warning: closedir() expects parameter 1 to be resource, boolean given in /srv/www/sisb/public_html/wp-content/plugins/WP-SISB/wp-sisb.php on line 267
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...