Beispiel #1
0
function imageThumb($src_field, $dst_field, $width, $height, $mode = 0)
{
    global $nc_core;
    if ($_FILES['f_' . $src_field] && !$_FILES['f_' . $src_field]['error']) {
        require_once $nc_core->INCLUDE_FOLDER . 'classes/nc_imagetransform.class.php';
        nc_ImageTransform::createThumb($src_field, $dst_field, $width, $height, $mode, NULL, 90);
    }
}
Beispiel #2
0
     }
 }
 $save_path = $FILES_FOLDER . $File_Path[$j] . ($fldFS[$i] == NC_FS_SIMPLE ? $tmpFile[$j] : $put_file_name);
 $save_path_preview = $FILES_FOLDER . $File_Path[$j] . 'preview_' . ($fldFS[$i] == NC_FS_SIMPLE ? $tmpFile[$j] : $put_file_name);
 @move_uploaded_file($srcFile, $save_path);
 $resize_format = nc_field_parse_resize_options($fldFmt[$i]);
 require_once $nc_core->INCLUDE_FOLDER . "classes/nc_imagetransform.class.php";
 if ($resize_format['use_preview']) {
     @nc_ImageTransform::imgResize($save_path, $save_path_preview, $resize_format['preview_width'], $resize_format['preview_height']);
 }
 if ($resize_format['use_resize']) {
     @nc_ImageTransform::imgResize($save_path, $save_path, $resize_format['resize_width'], $resize_format['resize_height']);
     $filesize = filesize($save_path);
 }
 if ($resize_format['use_crop']) {
     @nc_ImageTransform::imgCrop($save_path, $save_path, $resize_format['crop_x0'], $resize_format['crop_y0'], $resize_format['crop_x1'], $resize_format['crop_y1'], NULL, 90, 0, 0, $resize_format['crop_ignore'] ? $resize_format['crop_ignore_width'] : 0, $resize_format['crop_ignore'] ? $resize_format['crop_ignore_height'] : 0);
     $filesize = filesize($save_path);
 }
 // в этом случаe надо записать в базу
 if ($fldFS[$i] == NC_FS_PROTECTED) {
     $query = $db->query("INSERT INTO `Filetable`\n                                    (`Real_Name`, `File_Path`, `Virt_Name`, `File_Type`, `File_Size`, `Field_ID`, `Content_Disposition`)\n                             VALUES ('" . $db->escape($filename) . "', '/" . $db->escape($File_Path[$j]) . "', '" . $db->escape($put_file_name) . "', '" . $db->escape($filetype) . "',\n                                    '" . intval($filesize) . "', '" . intval($fldID[$i]) . "', '" . intval($fldDisposition[$i]) . "')");
     if ($query) {
         $filetable_lastid[] = $db->insert_id;
     }
 }
 $fldValue[$i] = str_replace('{filesize}', $filesize, $fldValue[$i]);
 // save file path in the $f_Field_url
 ${"f_" . $fld[$i] . "_url"} = $SUB_FOLDER . $HTTP_FILES_PATH . $File_Path[$j] . $tmpNewFile[$j];
 ${"f_" . $fld[$i] . "_preview_url"} = $SUB_FOLDER . $HTTP_FILES_PATH . $File_Path[$j] . 'preview_' . $tmpNewFile[$j];
 ${"f_" . $fld[$i] . "_name"} = $filename;
 ${"f_" . $fld[$i] . "_size"} = $filesize;
Beispiel #3
0
 /**
  *
  * @param string|int $class_id - ID компонента или название системной таблицы(User|Catalogue|Subdivision|Template)
  * @param string|int $field - название или ID поля в которое сохранять
  * @param int $message_id - ID объекта|пользователя|сайта|раздела|макета
  * @param array $file - массив с данными о файле из $_FILES либо
  *      path          — путь к файлу(/netcat/tmp/foto.jpg) или ссылка(http://example.com/foto.jpg)
  *      type          — mime-тип, попытается определить автоматически если не задан, по умолчанию image/jpeg
  *      name          — имя файла, возьмется из ссылки если не задано
  *      folder        — нестандартная папка в которую сохранить файл, только для стандартной ФС
  * @param bool $no еdit           - игнорировать настройки поля изменяющие файл
  * @param bool $message_put - режим работы внутри системы
  * @return array
  *      download_path — ссылка для скачивания под оригинальным именем (ссылка с "h_")
  *      url           — путь к файлу от корня сайта
  *      preview_url   — путь к превью файла от корня сайта
  *      name          — изначальное имя файла
  *      size          — размер
  *      type          — mime-тип
  */
 public function field_save_file($class_id, $field, $message_id, $file, $noеdit = false, $message_put = false)
 {
     $DOCUMENT_ROOT = nc_core('DOCUMENT_ROOT');
     $FILES_FOLDER = nc_core('FILES_FOLDER');
     $files_http_path = nc_core('SUB_FOLDER') . nc_core('HTTP_FILES_PATH');
     $db = nc_core('db');
     $message_id = intval($message_id);
     $component = new nc_Component($class_id);
     $systemTableID = $component->get_system_table_id();
     $systemTableName = $systemTableID ? $class_id : '';
     $fields = $component->get_fields(NC_FIELDTYPE_FILE);
     if (!empty($fields)) {
         foreach ($fields as $v) {
             if ($v['id'] == $field || $v['name'] == $field) {
                 $rawformat = $v['format'];
                 $field_id = $v['id'];
                 $field_name = $v['name'];
             }
         }
     } else {
         return null;
         //wrong class or field
     }
     if (!$systemTableID) {
         $msg = $db->get_row("SELECT `Sub_Class_ID`, `Subdivision_ID` FROM `Message{$class_id}` WHERE `Message_ID` = '{$message_id}'", ARRAY_A);
     } else {
         $msg = $db->get_row("SELECT COUNT(*) FROM `{$systemTableName}` WHERE `{$systemTableName}_ID` = {$message_id}", ARRAY_A);
     }
     if (empty($msg)) {
         return null;
         //wrong message
     }
     $result = array();
     #delete old file
     require_once $this->core->INCLUDE_FOLDER . "s_files.inc.php";
     DeleteFile($field_id, $field_name, $class_id, $systemTableName, $message_id);
     $format = nc_field_parse_format($rawformat, NC_FIELDTYPE_FILE);
     $fileurl = $file['path'];
     $filesrc = $file['tmp_name'];
     if (!$fileurl && !$filesrc) {
         return null;
         //no file to save
     }
     if (!$filesrc && $fileurl && !(preg_match("~^[^=]+://~", $fileurl) && ($buf = @file_get_contents($fileurl))) && !file_exists($DOCUMENT_ROOT . $fileurl)) {
         //и по внутренней нет
         return null;
     }
     $filename = $file['name'] ? $file['name'] : substr($fileurl, strrpos($fileurl, '/') + 1);
     $filename = str_replace(array('<', '>'), '_', $filename);
     $filetype = $file['type'];
     $filesize = $file['size'];
     $folder = trim($file['folder'], '/');
     // расширение файла
     $ext = substr($filename, strrpos($filename, "."));
     if (!$systemTableID) {
         $File_Path = $msg['Subdivision_ID'] . "/" . $msg['Sub_Class_ID'] . "/";
     } elseif ($systemTableID == 1) {
         $File_Path = "c/";
     } elseif ($systemTableID == 3) {
         $File_Path = "u/";
     } elseif ($systemTableID == 4) {
         $File_Path = "t/";
     } else {
         $File_Path = $message_id ? $message_id . "/" : "";
         //sic! why eval?
         $File_PathNew = "\$message/";
     }
     // будущее имя файла на диске + путь
     switch ($format['fs']) {
         case NC_FS_PROTECTED:
             // hash
             // имя файла
             $put_file_name = md5($filename . date("H:i:s d.m.Y") . uniqid("netcat"));
             break;
         case NC_FS_ORIGINAL:
             // пользователь сам указал папку
             if ($folder && preg_match("/^[a-z][a-z0-9\\/]+\$/is", $folder)) {
                 $File_Path = $folder . "/";
             }
             // сгенерировать имя файла
             $put_file_name = nc_get_filename_for_original_fs($filename, $FILES_FOLDER . $File_Path);
             $db_string_path = ":" . ($File_PathNew ? $File_PathNew : $File_Path) . $put_file_name;
             break;
         case NC_FS_SIMPLE:
             // FieldID_MessageID.ext
             $File_Path = '';
             // в папку netcat_files
             //sic! why eval?
             $put_file_name = $field_id . ($message_put ? '_$message' : "_" . $message_id) . $ext;
             break;
     }
     $this->create_dir($FILES_FOLDER . $File_Path);
     //для простой ФС нужно скопировать временный файл
     //он будет обрабатываться и после добавления объекта переименован в FieldID_MessageID.ext
     //при добавлении объекта или раздела пока неизвестен путь, поэтому файл попадет в папку netcat_files и потом перенесен
     $save_mame = $format['fs'] == NC_FS_SIMPLE && $message_put ? $filesrc : $put_file_name;
     $save_path = $FILES_FOLDER . $File_Path . $save_mame;
     $save_path_preview = $FILES_FOLDER . $File_Path . 'preview_' . $save_mame;
     if ($filesrc) {
         @move_uploaded_file($filesrc, $save_path);
     } else {
         if ($buf) {
             @file_put_contents($save_path, $buf);
         } else {
             @copy($DOCUMENT_ROOT . $fileurl, $save_path);
         }
     }
     $resize_format = nc_field_parse_resize_options($rawformat);
     require_once $this->core->INCLUDE_FOLDER . "classes/nc_imagetransform.class.php";
     if (!$noеdit) {
         if ($resize_format['use_preview']) {
             @nc_ImageTransform::imgResize($save_path, $save_path_preview, $resize_format['preview_width'], $resize_format['preview_height']);
         }
         if ($resize_format['use_resize']) {
             @nc_ImageTransform::imgResize($save_path, $save_path, $resize_format['resize_width'], $resize_format['resize_height']);
             $filesize = filesize($save_path);
         }
         if ($resize_format['use_crop']) {
             @nc_ImageTransform::imgCrop($save_path, $save_path, $resize_format['crop_x0'], $resize_format['crop_y0'], $resize_format['crop_x1'], $resize_format['crop_y1'], NULL, 90, 0, 0, $resize_format['crop_ignore'] ? $resize_format['crop_ignore_width'] : 0, $resize_format['crop_ignore'] ? $resize_format['crop_ignore_height'] : 0);
             $filesize = filesize($save_path);
         }
     }
     $filesize = $filesize ? $filesize : filesize($save_path);
     $filetype = $filetype ? $filetype : ($filetype = $this->_guess_content_type($save_path) ? $filetype : "image/jpeg");
     // для защищенной надо записать файл в базу
     if ($format['fs'] == NC_FS_PROTECTED) {
         $query = $db->query("INSERT INTO `Filetable`\n                            (`Real_Name`, `File_Path`, `Virt_Name`, `File_Type`, `File_Size`, `Field_ID`, `Content_Disposition`, `Message_ID`)\n                     VALUES ('" . $db->escape($filename) . "', '/" . $db->escape($File_Path) . "', '" . $db->escape($put_file_name) . "', '" . $db->escape($filetype) . "',\n                            '" . intval($filesize) . "', '" . intval($field_id) . "', '" . intval($format['disposition']) . "', '" . $message_id . "')");
         if ($query) {
             $filetable_lastid = $db->insert_id;
             $result['download_path'] = $files_http_path . $File_Path . 'h_' . $put_file_name;
         }
     }
     $db_string = $filename . ":" . $filetype . ":" . $filesize . $db_string_path;
     $result['url'] = $files_http_path . $File_Path . $put_file_name;
     $result['preview_url'] = $resize_format['use_preview'] ? $files_http_path . $File_Path . 'preview_' . $put_file_name : "";
     $result['name'] = $filename;
     $result['size'] = $filesize;
     $result['type'] = $filetype;
     if (!$message_put) {
         //запишем в объект сущности
         $query = $db->query("UPDATE `" . ($systemTableID ? $systemTableName : "Message" . $class_id) . "`\n                                    SET `{$field_name}` = '" . $db->escape($db_string) . "'\n                                        WHERE `" . ($systemTableID ? $systemTableName : "Message") . "_ID` = {$message_id}");
     } else {
         //данные для использования в скриптах добавления/изменения после message_put.php
         $result['FileFS'] = $format['fs'];
         $result['tmpNewFile'] = $put_file_name;
         $result['File_Path'] = $File_Path;
         $result['File_PathNew'] = $File_PathNew;
         $result['filetable_lastid'] = $filetable_lastid;
         $result['fldValue'] = $db_string;
     }
     return $result;
 }
 public function save($value)
 {
     $nc_core = nc_Core::get_object();
     parent::save($value);
     if ($this->upload && $this->resize_w && $this->resize_h) {
         require_once $nc_core->INCLUDE_FOLDER . "classes/nc_imagetransform.class.php";
         nc_ImageTransform::imgResize($this->filepath, $this->filepath, $this->resize_w, $this->resize_h);
         clearstatcache(true, $this->filepath);
         $this->filesize = filesize($this->filepath);
         if ($this->filesize) {
             $paths = explode('/', $this->filepath);
             $put_file_name = $paths[count($paths) - 1];
             $this->value = $put_file_name . ':' . $this->filetype . ':' . $this->filesize . ':cs/' . $put_file_name;
             $this->filename = $put_file_name;
         } else {
             $this->value = '';
         }
     }
 }