getCurVal() ) { $html .= ''; } $html .= ''; $html .= ''; if ( $this->getCurVal() ) { $html .= '
'; } return $html; } function lPost() { if ( substr( $this->attr_name, -8 ) == '_preview' ) { return; } if ($_POST[$this->attr_name . '_del']) { $this->obj->set( $this->attr_name, 0 ); } if ($_POST[$this->attr_name]) { $this->obj->set( $this->attr_name, $_POST[$this->attr_name] ); } $file = $_FILES[$this->attr_name]; if (isset($file['error']) && !$file['error']) { require_once (_CORE_DIR . 'image.transform.core.php'); $tmpObj = new cobject( '_sys_files' ); $file = $_FILES[$this->attr_name]; $fileContent = file_get_contents($file['tmp_name']); // Имя файла основано на содержимом $fname = md5($fileContent); $fpath = substr($fname,0,2); $fpath2 = substr($fname,2,2); @mkdir( _FILES_DIR_ . $fpath . '/' . $fpath2, 0777, true ); $fname = $fpath .'/' . $fpath2 . '/' . $fname; $toSize = $this->obj->attrs[$this->attr_name]['templ']; if (!file_exists(_FILES_DIR_ . $fname .'_'. $toSize) ) { $im = imagecreatefromstring($fileContent); // Сохраняем картинку $res = imagejpeg($im, _FILES_DIR_ . $fname.'_' , 95 ); //Ресайзим если нужно if ($toSize != "") { $p = explode('x', $toSize); if (count($p) == 2) { $tr = new imageTransform(_FILES_DIR_ . $fname .'_', 'image/jpeg'); $tr->resize($p[0], $p[1], true); $tr->save(_FILES_DIR_ .$fname .'_'. $toSize); } } } // Сохраняем в базу $fobj = new cobject('_sys_files'); $fobj->set('filename', $fname . '_'. $toSize); $fobj->set('ext','image/jpeg'); $fobj->set('realname', $file['name']); $fobj->save(); // Сохраняем в объект $this->obj->set( $this->attr_name, $fobj->id ); // Автопревью if ( isset($this->obj->attrs[$this->attr_name.'_preview']) && $this->obj->attrs[$this->attr_name.'_preview']['templ'] ) { $pre_size = $this->obj->attrs[$this->attr_name.'_preview']['templ']; if ($pre_size != "" ) { // Сохраняем в базу $fobj = new cobject('_sys_files'); $fobj->set('filename', $fname . '_' . $pre_size ); $fobj->set('ext','image/jpeg'); $fobj->set('realname', 'preview_'.$file['name']); $fobj->save(); $this->obj->set( $this->attr_name.'_preview', $fobj->id ); copy(_FILES_DIR_.$fname . '_'. $toSize, _FILES_DIR_.$fname.'_' . $pre_size ); $p = explode('x',$pre_size); $tr = new imageTransform(_FILES_DIR_ . $fname.'_' . $pre_size, 'image/jpeg'); $tr->resize($p[0], $p[1], true); $tr->save(_FILES_DIR_ .$fname.'_' . $pre_size ); } } } } function render_text( $crop = false ) { if ($crop) { $val = ''; } else { $val = $this->getCurVal(); $val = getImagePath($val); } return $val; } } ?>