Beispiel #1
0
                if ($length > 64 && strlen($rename_name) < 64) {
                    $s = substr($s, 0, 63 - strlen($rename_name));
                    $rename_name = $s . "_" . $rename_name;
                }
                $existingFile->Rename("{$path}/{$rename_name}");
                $info = 'Файл был заменен';
                $old_link = WDCPREFIX . '/' . $path . '/' . $rename_name;
            }
            $cf->server_root = 1;
            $cf->max_size = dav_file_upload::MAX_FILE_SIZE;
            $cf->MoveUploadedFile($path . '/', true, $destname);
            $err = is_string($cf->error[0]) ? $cf->error : $cf->error[0];
            if ($err == '') {
                $link = WDCPREFIX . '/' . $cf->path . $cf->name;
                $name = WDCPREFIX . '/' . $cf->path . $cf->name;
                $info = 'Файл был загружен';
                //добавляем запись в таблицу replace_file_log
                dav_file_upload::addRecord($cf->id, $cf->name, $rename_name);
            }
        } else {
            $error_folder = 'Нет такого каталога';
        }
        include dirname(__FILE__) . "/uploadform.php";
        return;
}
if ($view == 'form') {
    include dirname(__FILE__) . "/uploadform.php";
} else {
    $css_file = array('moderation.css', 'nav.css');
    include $rpath . 'template.php';
}
 **/
require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/stdf.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/CFile.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/dav_file_upload.php';
if (!hasPermissions('admin')) {
    header('Location: /404.php');
    exit;
}
$srcdir = $_SERVER['DOCUMENT_ROOT'] . '/about';
$ls = scandir($srcdir);
foreach ($ls as $item) {
    if ($item != '.' && $item !== '..' && !is_dir("{$srcdir}/{$item}")) {
        $filedata = array('name' => $item, 'tmp_name' => "{$srcdir}/{$item}", 'size' => filesize("{$srcdir}/{$item}"));
        $srcfile = new CFile($filedata);
        $srcfile->unlinkOff = true;
        $path = 'about/documents';
        $destfile = new CFile("{$path}/{$item}", dav_file_upload::FILE_TABLE);
        $rename_name = '';
        if ($destfile->id) {
            $ext = $destfile->getext($destfile->name);
            $tmp = $destfile->secure_tmpname($path . '/', '.' . $ext);
            $rename_name = substr_replace($tmp, '', 0, strlen($path) + 1);
            $destfile->Rename("{$path}/{$rename_name}");
        }
        $srcfile->server_root = 1;
        $srcfile->max_size = dav_file_upload::MAX_FILE_SIZE;
        $r = $srcfile->MoveUploadedFile($path . '/', true, $item);
        dav_file_upload::addRecord($srcfile->id, $srcfile->name, $rename_name);
        echo "Copy {$srcdir}/{$item} " . WDCPREFIX . '/' . $path . '/' . $item . '<br><br>';
    }
}