function GetUploadedFile($file, $file_name, $file_dir = 'files', $resample = 0, $quality = '85') { if (!is_writable($file_dir)) { die(str('e_not_writable') . " (" . $file_dir . ")"); } $file_dir = preg_replace("~(/\$)~", "", $file_dir); $file_name = GetPureName($file_name); if ($file) { if (!$resample || 1) { # find first unexisting filename $counter = 0; $dot = strrpos($file_name, '.'); $fbase = substr($file_name, 0, $dot); $fext = substr($file_name, $dot); while (is_file($file_dir . '/' . $file_name)) { $counter++; $file_name = $fbase . "_" . $counter . $fext; } } @move_uploaded_file($file, $file_dir . '/' . $file_name) or die(str('e_upload') . " (" . $file_dir . "/" . $file_name . ")"); @chmod($file_dir . '/' . $file_name, 0775); # resample image if ($resample) { return ResampleImage($file_dir, $file_name, $resample, $quality); } else { return $file_name; } } }
function EditDownload() { $dir = get("down_dir", 'null', 'gp'); $vdir = $this->verifyDir($dir); if (!is_array($vdir)) { $vdir = $this->getStartDir(); } $dir = $vdir['dir']; $width = get("width", 0, 'gp'); $height = get("height", 0, 'gp'); $file = isset($_FILES['file']) ? $_FILES['file'] : ""; if ($width != 0 || $height != 0) { $size = array($width, $height); } if (!empty($file)) { # находим несуществующее имя $file_name = GetPureName($file['name']); # уменьшаем рассширение файла, для номрального просмотра в fm $dot = strrpos($file_name, '.'); $ext = strtolower(substr($file_name, $dot, strlen($file_name) - $dot)); if (in_array($ext, $this->deny)) { echo "<script>alert('Вы не можете закачивать файлы с таким расширением.');</script>"; return; } $file_name = substr($file_name, 0, $dot) . $ext; if (file_exists($this->SlashSep($dir, $file_name))) { $num = 1; while (file_exists($this->SlashSep($dir, new_file_name($file_name, '[' . $num . ']')))) { $num++; } $file_name = new_file_name($file_name, '[' . $num . ']'); } $file_put = $this->SlashSep($dir, $file_name); if (!move_uploaded_file($file['tmp_name'], $file_put)) { echo "<script>alert('Ошибка загрузки файла');</script>"; } @chmod($file_put, FILES_MOD); @chown($file_put, fileowner($_SERVER['SCRIPT_FILENAME'])); @chgrp($file_put, filegroup($_SERVER['SCRIPT_FILENAME'])); # Ресайз if (!empty($size)) { $quality = sql_getValue('SELECT value FROM strings WHERE name="resize_quality" AND module="site" AND root_id=' . domainRootId() . ' AND lang="' . lang() . '"'); if (!$quality) { $quality = 85; } $file_name = ResampleImage($dir, $file_name, $size, false, $quality); } if (get('watermark', false, 'gp')) { $data = $this->config; $watermark = $data['module']['watermark_file']; if (!is_file(".." . $watermark)) { echo "<script>alert('Не найден файл с водяным знаком!');</script>"; die; } $this->addWaterMark($file_name, ".." . $watermark); } } echo "\n\t\t<script>\n\t\tparent.openDir('" . $dir . "');\n\t\tparent.hideDownloadFrom();\n\t\tparent.stopMainLoad();\n\t\t</script>\n\t\t"; }
/** * Вызывается перед сохранением в базу * * @param array $fld * @return array */ function ElemRedactBefore($fld) { if (!$fld['is_link']) { $fld['redirect'] = ''; } $fld = parent::ElemRedactBefore($fld); $error = ""; $page_id = get('id', 0, 'gp'); $page_pid = get('pid', 0, 'gp'); if ($page_pid) { $parent = sql_getRow("SELECT dir, pids, level, root_id FROM " . $this->elem_table . " WHERE id=" . $page_pid); } else { $page_pid = sql_getValue("SELECT pid FROM `" . $this->elem_table . "` WHERE id=" . $page_id); $parent = sql_getRow("SELECT dir, pids, level, root_id FROM " . $this->elem_table . " WHERE id=" . $page_pid); } if (!$page_id) { // создание нового раздела $auto = sql_getRow("SHOW TABLE STATUS LIKE '" . $this->elem_table . "'"); if ($auto['Auto_increment']) { $new_id = $auto['Auto_increment']; } if ($page_pid == $parent['root_id']) { $fld['level'] = 1; } else { $fld['level'] = $parent['level'] + 1; } $fld['priority'] = sql_getValue("SELECT MAX(priority) FROM `" . $this->elem_table . "` WHERE pid=" . $page_pid) + 1; } if (!$fld['page']) { $fld['page'] = $page_id ? $page_id : $new_id; } else { $fld['page'] = GetPureName(trim($fld['page'])); } $fld['page'] = strtolower($fld['page']); if ($page_pid != $parent['root_id']) { # pids $pids = explode('/', $parent['pids']); if (!$pids[0]) { array_shift($pids); } if (!$pids[count($pids) - 1]) { array_pop($pids); } $pids[] = $page_pid; $fld['pids'] = '/' . join('/', $pids) . '/'; # dir $fld['dir'] = $parent['dir'] . $fld['page'] . '/'; } else { # pids $fld['pids'] = '/' . $page_pid . '/'; $fld['dir'] = '/' . $fld['page'] . '/'; } //укажем root_id $fld['root_id'] = $parent['root_id']; # изменим next у родителя sql_query("UPDATE tree SET next='1' WHERE id='" . (isset($parent['id']) ? $parent['id'] : $page_pid) . "'"); # Проверка на существование dir $check = sql_getValue("SELECT id FROM " . $this->elem_table . " WHERE root_id='" . $parent['root_id'] . "' AND dir='" . $fld['dir'] . "'"); if ($check && $check != $page_id) { $error_tab = $k; $error = "Раздел с таким URL уже существует"; } return array('fld' => $fld, '_error_text' => $error); }
function GetUploadedFile($file, $file_name, $file_dir = 'files', $resample = 0, $quality = '85') { if (!is_writable($file_dir)) { Header("Location: " . $_SERVER["PHP_SELF"] . "?page=" . $this->name . "&dir=" . $_POST['dir'] . "&err=5"); exit; } $file_dir = preg_replace("~(/\$)~", "", $file_dir); $file_name = GetPureName($file_name); if ($file) { if (!$resample || 1) { # find first unexisting filename $counter = 0; $dot = strrpos($file_name, '.'); $fbase = substr($file_name, 0, $dot); $fext = substr($file_name, $dot); while (is_file($file_dir . '/' . $file_name)) { $counter++; $file_name = $fbase . "_" . $counter . $fext; } } if ($resample) { $size = $GLOBALS['resamle_options'][$resample]; } if (!move_uploaded_file($file, $file_dir . '/' . $file_name)) { Header("Location: " . $_SERVER["PHP_SELF"] . "?page=" . $this->name . "&dir=" . $_POST['dir'] . "&err=6"); exit; //or die(str('e_upload')." (".$file_dir."/".$file_name.")"); } @chmod($file_dir . '/' . $file_name, 0775); # resample image if ($resample) { return ResampleImage($file_dir, $file_name, $size, false, $quality); } else { return $file_name; } } }