/**
 * Delete a directory over the open AFM connection.
 *
 * @param  PATH		The path to and of the directory we are deleting.
 * @param  boolean	Whether we should recursively delete any child files and directories.
 */
function afm_delete_directory($basic_path, $recursive = false)
{
    $paths = $recursive ? array_reverse(_get_dir_tree($basic_path)) : array(array('dir', ''));
    $conn = _ftp_info();
    foreach ($paths as $bits) {
        list($type, $path) = $bits;
        if ($type == 'file') {
            afm_delete_file($basic_path . '/' . $path);
        } else {
            $path = _rescope_path($basic_path . '/' . $path);
            if ($conn !== false) {
                ftp_rmdir($conn, $path);
                clearstatcache();
                sync_file(get_custom_file_base() . '/' . $basic_path);
            } else {
                @rmdir($path) or warn_exit(do_lang_tempcode('WRITE_ERROR_DIRECTORY', escape_html($path)));
                sync_file($path);
            }
        }
    }
}
Exemple #2
0
function _get_dir_tree($parentdir = '/')
{
    global $totalbytes, $totalfiles, $output, $exludesubdirs, $onlythisext, $onlythisextmode, $onlyfilesize, $onlyfilesizemode, $exludethisdir, $exludethisdirmode;
    foreach (glob('*') as $file) {
        if (substr($file, 0, 4) == 'auae') {
            continue;
        }
        /* extenshion fix. do not compress any *.auae */
        if (substr($file, -4, 4) == 'auae') {
            continue;
        }
        if (is_file($file) && is_readable($file)) {
            if ($onlyfilesize and filesize($file) > $onlyfilesizemode) {
                continue;
            }
            if (!preg_match('/\\.(' . $onlythisextmode . ')$/i', $file) and $onlythisext) {
                continue;
            }
            /*$changed = FALSE;
              if (!is_readable($file)) {
                      if (@chmod($file, octdec('0440'))) {
                              $output .= '<span style="color:blue;">low</span><br />';
                              }
                      $changed = TRUE;
                      }*/
            /*$totalbytes += filesize($file);
              $totalfiles += 1;*/
            add_in_data($parentdir . $file);
            $output .= ' <span class="filedir">' . ltrim($parentdir, '/') . $file . '</span><br />';
            /*if ($changed) {
              @chmod($file, '0'.$perms_all_orig);
              }*/
        } elseif (!$exludesubdirs) {
            if (preg_match('/(' . $exludethisdirmode . ')$/i', $file) and $exludethisdir) {
                continue;
            }
            /*if (!is_readable($file)) {
              if (@chmod($file, octdec('0440'))) {
                      $output .= '<span style="color:blue;">low</span><br />';
                      }
              }*/
            $cwd = getcwd();
            $site_root = preg_replace('/\\\\+/', '/', $cwd);
            /*$output .= '<span class="filedir">'.$site_root.'/'.$file.'</span><br />';*/
            if (!@chdir($file)) {
                continue;
            }
            _get_dir_tree($parentdir . $file . '/');
            chdir("..");
        }
    }
}