Beispiel #1
0
function autoedit_createPath($p, $path = '')
{
    //путь до файла или дирректории со * или без, возвращается тот же путь без звёздочки
    //Если путь приходит от пользователя нужно проверять и префикс infra/data добавляется автоматически чтобы ограничить места создания
    //if(preg_match("/\/\./",$ifolder))return err($ans,'Path should not contain points at the beginning of filename /.');
    //if(!preg_match("/^\*/",$ifolder))return err($ans,'First symbol should be the asterisk *.');
    if (is_string($p)) {
        $p = Path::resolve($p);
        $p = explode('/', $p);
        $f = array_pop($p);
        //достали файл или пустой элемент у дирректории
        $f = Path::tofs($f);
    } else {
        $f = '';
    }
    $dir = array_shift($p);
    //Создаём первую папку в адресе
    $dir = Path::tofs($dir);
    if ($dir) {
        if (!is_dir($path . $dir)) {
            $r = mkdir($path . $dir);
        } else {
            $r = true;
        }
        if ($r) {
            return autoedit_createPath($p, $path . $dir . '/') . $f;
        } else {
            throw Exception('Ошибка при работе с файловой системой');
        }
    }
    return $path . $dir . '/' . $f;
}
Beispiel #2
0
     $ans['oldfolder'] = $parent;
     //Папка в которой можно увидеть обрабатываемую папку
     $ans['oldname'] = $name;
     $ans['content'] = Load::loadTEXT($id);
     return Ans::ret($ans);
 } else {
     $file = $id;
     //$isdir=Path::theme($file,'sdn');
     //if($isdir) return infra_echo($ans,'Существует папка с именем как у файла '.$id);
     $isfile = Path::theme($file);
     if (!$isfile) {
         if (!autoedit_ext($file)) {
             $file .= '.tpl';
         }
         $ans['msg'] .= 'Файл был создан<br>';
         $file = autoedit_createPath($file);
         if (!$file) {
             return Ans::err($ans, 'Не удалось создать путь до файла' . $id);
         }
     } else {
         $file = $isfile;
     }
     $r = file_put_contents($file, $_REQUEST['content']);
     //autoedit_setLastFolderUpdate($file);
     if (!$r) {
         return Ans::err($ans, 'Неудалось сохранить файл');
     }
     //$ans['noclose']=1;
     //$ans['autosave']=0;
     $ans['msg'] .= 'Cохранено';
     return Ans::ret($ans);