예제 #1
0
 public function getSQLValue($name = '')
 {
     global $PRJ_DIR;
     $name = $name ? $name : $this->getName();
     $ret = CUtils::_postVar($name . '_oldValue');
     if ($ret && CUtils::_postVar($name . '_delete')) {
         if ($ret != '/img/lib/empty_photo.gif' && $ret != '') {
             @unlink($PRJ_DIR . $ret);
             if (isset($this->props['sizes'])) {
                 $path_parts = pathinfo($PRJ_DIR . $ret);
                 $asizes = explode(',', $this->props['sizes']);
                 foreach ($asizes as $sz) {
                     $asz = explode('|', $sz);
                     if (sizeof($asz) == 2) {
                         @unlink($path_parts['dirname'] . '/' . $asz[0] . '_' . $path_parts['basename']);
                     }
                 }
             }
         }
         $ret = '';
     }
     if (is_array($_FILES) && sizeof($_FILES) > 0 && isset($_FILES[$name]) && $_FILES[$name]['name'] != '') {
         if ($ret && $ret != '/img/lib/empty_photo.gif') {
             @unlink($PRJ_DIR . $ret);
             if (isset($this->props['sizes'])) {
                 $path_parts = pathinfo($PRJ_DIR . $ret);
                 $asizes = explode(',', $this->props['sizes']);
                 foreach ($asizes as $sz) {
                     $asz = explode('|', $sz);
                     if (sizeof($asz) == 2) {
                         @unlink($path_parts['dirname'] . '/' . $asz[0] . '_' . $path_parts['basename']);
                     }
                 }
             }
         }
         $dest = CUtils::getNextFileName('/upload/' . strtolower(CUtils::translitStr($_FILES[$name]['name'])));
         @move_uploaded_file($_FILES[$name]['tmp_name'], $PRJ_DIR . $dest);
         $ret = $dest;
         $this->afterUpload($ret);
     }
     return $ret;
 }
예제 #2
0
파일: file.php 프로젝트: rawork/colors-life
 public function getSQLValue($name = '')
 {
     global $PRJ_DIR;
     $name = $name ? $name : $this->getName();
     $ret = $_REQUEST[$name . '_oldValue'];
     if ($ret && CUtils::_postVar($name . '_delete')) {
         @unlink($PRJ_DIR . $ret);
         $ret = '';
     }
     if (is_array($_FILES) && sizeof($_FILES) > 0 && isset($_FILES[$name]) && $_FILES[$name]['name'] != '') {
         if ($ret) {
             @unlink($PRJ_DIR . $ret);
         }
         $dest = CUtils::getNextFileName('/upload/' . strtolower(CUtils::translitStr($_FILES[$name]['name'])));
         move_uploaded_file($_FILES[$name]['tmp_name'], $PRJ_DIR . $dest);
         $ret = $dest;
         $this->afterUpload($ret);
     }
     return $ret;
 }
예제 #3
0
 public function getSQLValue($name = '')
 {
     global $VERSION_QUANTITY, $PRJ_DIR;
     $name = $name ? $name : $this->getName();
     $ret = CUtils::_postVar($name . '_oldValue');
     $date_stamp = date('Y_m_d_H_i_s');
     $values = '';
     if ($ret && CUtils::_postVar($name . '_delete')) {
         $backup_ret = str_replace('/templates/', '/templates/backup/', $ret);
         @copy($PRJ_DIR . $ret, $PRJ_DIR . $backup_ret . $date_stamp . '.bak');
         @unlink($PRJ_DIR . $ret);
         $values = "'" . $this->props['cls'] . "','" . $this->getName() . "'," . $this->dbId . ",NOW(),'" . $backup_ret . $date_stamp . '.bak' . "'";
         $ret = '';
     } elseif ($ret && CUtils::_postVar($name . '_version', true, 0)) {
         $backup_ret = str_replace('/templates/', '/templates/backup/', $ret);
         @copy($PRJ_DIR . $ret, $PRJ_DIR . $backup_ret . $date_stamp . '.bak');
         @unlink($PRJ_DIR . $ret);
         $values = "'" . $this->props['cls'] . "','" . $this->getName() . "'," . $this->dbId . ",NOW(),'" . $backup_ret . $date_stamp . '.bak' . "'";
         $ver = $GLOBALS['db']->getItem('templates_version', "SELECT * FROM templates_version WHERE id=" . CUtils::_postVar($name . '_version', true, 0));
         @copy($PRJ_DIR . $ver['file'], $PRJ_DIR . $ret);
     } elseif ($ret) {
         $f = fopen($PRJ_DIR . $ret . '_new', 'w');
         fwrite($f, $_POST[$name . '_temp']);
         fclose($f);
         if (md5_file($PRJ_DIR . $ret . '_new') != md5_file($PRJ_DIR . $ret)) {
             $backup_ret = str_replace('/templates/', '/templates/backup/', $ret);
             @copy($PRJ_DIR . $ret, $PRJ_DIR . $backup_ret . $date_stamp . '.bak');
             $values = "'" . $this->props['cls'] . "','" . $this->getName() . "'," . $this->dbId . ",NOW(),'" . $backup_ret . $date_stamp . '.bak' . "'";
             @copy($PRJ_DIR . $ret . '_new', $PRJ_DIR . $ret);
         }
         @unlink($PRJ_DIR . $ret . '_new');
     }
     if (CUtils::_postVar($name . '_cre')) {
         $ret = CUtils::_postVar($name);
         if (trim($ret) != '') {
             $dest = CUtils::getNextFileName('/templates' . (isset($this->props['basepath']) ? $this->props['basepath'] : '') . '/' . CUtils::translitStr($ret));
             $ret = $dest;
             $f = fopen($PRJ_DIR . $ret, 'w');
             fwrite($f, $_POST[$name . "_temp"]);
             fclose($f);
             chmod($PRJ_DIR . $ret, 0666);
         }
     } elseif (is_array($_FILES) && sizeof($_FILES) > 0 && isset($_FILES[$name]) && $_FILES[$name]['name'] != '') {
         if ($ret) {
             $backup_ret = str_replace('/templates/', '/templates/backup/', $ret);
             @copy($PRJ_DIR . $ret, $PRJ_DIR . $backup_ret . $date_stamp . '.bak');
             @unlink($PRJ_DIR . $ret);
             $values = "'" . $this->props['cls'] . "','" . $this->getName() . "'," . $this->dbId . ",NOW(),'" . $backup_ret . $date_stamp . '.bak' . "'";
         }
         $dest = CUtils::getNextFileName('/templates' . (isset($this->props['basepath']) ? $this->props['basepath'] : '') . '/' . $_FILES[$name]['name']);
         move_uploaded_file($_FILES[$name]['tmp_name'], $PRJ_DIR . $dest);
         chmod($PRJ_DIR . $dest, 0666);
         $ret = $dest;
     }
     if ($values) {
         $vers = $GLOBALS['db']->getItems('select_version', "SELECT * FROM templates_version WHERE cls='" . $this->props['cls'] . "' AND fld='" . $this->getName() . "' AND rc=" . $this->dbId . ' ORDRER BY id');
         if (sizeof($vers) >= __VERSION_QUANTITY) {
             $GLOBALS['db']->execQuery('templates_version', 'DELETE FROM templates_version WHERE id=' . $vers[0]['id']);
         }
         $db_ret = $GLOBALS['db']->execQuery('add_version', 'INSERT INTO templates_version(cls,fld,rc,credate,file) VALUES(' . $values . ')');
         //var_dump($db_ret, 'INSERT INTO templates_version(cls,fld,rc,credate,file) VALUES('.$values.')');
         //die();
     }
     return $ret;
 }
예제 #4
0
 function insertArray(&$a)
 {
     global $db;
     $names = $values = '';
     foreach ($a as $k => $v) {
         foreach ($this->fields as $f) {
             if ($k && $f['name'] == $k) {
                 $names = ($names ? $names . ', ' : '') . $f['name'];
                 if ($a[$f['name']] && ($f['type'] == 'image' || $f['type'] == 'file' || $f['type'] == 'template')) {
                     $ft = $this->createFieldType($f);
                     $dest = CUtils::getNextFileName($v);
                     @copy($GLOBALS['PRJ_DIR'] . $v, $GLOBALS['PRJ_DIR'] . $dest);
                     $values = ($values ? $values . ', ' : '') . "'" . $dest . "'";
                     if ($f['type'] == 'image' && isset($ft->props['sizes'])) {
                         $path_parts = pathinfo($a[$ft->getName()]);
                         $asizes = explode(',', $ft->props['sizes']);
                         foreach ($asizes as $sz) {
                             $asz = explode('|', $sz);
                             if (sizeof($asz) == 2) {
                                 $v = $path_parts['dirname'] . '/' . $asz[0] . '_' . $path_parts['basename'];
                                 $dest = CUtils::getNextFileName($v);
                                 @copy($GLOBALS['PRJ_DIR'] . $v, $GLOBALS['PRJ_DIR'] . $dest);
                             }
                         }
                     }
                 } else {
                     $values = ($values ? $values . ', ' : '') . "'" . $v . "'";
                 }
                 break;
             }
         }
     }
     $ret = $this->insert($names, $values);
     $iLastInsertID = $db->getInsertID();
     if ($this->props['multifile']) {
         $sql = "SELECT * FROM system_files WHERE record_id={$a['id']} AND table_name='" . $this->getDBTableName() . "'";
         $photos = $db->getItems('get_system_files', $sql);
         foreach ($photos as $photo) {
             $filepath = $photo['file'];
             $dest = CUtils::getNextFileName($filepath);
             @copy($GLOBALS['PRJ_DIR'] . $filepath, $GLOBALS['PRJ_DIR'] . $dest);
             unset($photo['id']);
             $photo['file'] = $dest;
             $photo['credate'] = date("Y-m-d H:i:s");
             $photo['record_id'] = $iLastInsertID;
             $names = implode(',', array_keys($photo));
             array_walk($photo, "fillValue");
             $values = implode(',', $photo);
             $sql = "INSERT INTO system_files ({$names}) VALUES ({$values})";
             $db->execQuery($this->getDBTableName(), $sql);
         }
     }
     //exit;
     return $ret;
 }
예제 #5
0
 public static function getNextFileName($name, $counter = 0)
 {
     preg_match('/([^\\.]+).(.+)/', $name, $regs);
     $newName = $counter ? $regs[1] . '_' . $counter . '.' . $regs[2] : $name;
     return @file_exists($GLOBALS['PRJ_DIR'] . $newName) ? CUtils::getNextFileName($name, $counter + 1) : $newName;
 }
예제 #6
0
             break;
         case '8':
             $error = 'Загрузка файла прервана';
             break;
         case '999':
         default:
             $error = 'Не известный код ошибки';
     }
 } elseif (empty($_FILES[$fileElementName]['tmp_name'][$i]) || $_FILES[$fileElementName]['tmp_name'][$i] == 'none') {
     $error = 'Файлы не загружены..';
 } else {
     /*if (file_exists($upload_path . $_FILES[$fileElementName]['name'][$i])){
     			$error = $_FILES[$fileElementName]['name'][$i] . " уже существует. ";
     		} else {*/
     $msg = " File Name: " . $_FILES[$fileElementName]['name'][$i] . "<br/>";
     $fileref = CUtils::getNextFileName($upload_ref . $_FILES[$fileElementName]['name'][$i]);
     move_uploaded_file($_FILES[$fileElementName]['tmp_name'][$i], $GLOBALS['PRJ_DIR'] . $fileref);
     $filename = $_FILES[$fileElementName]['name'][$i];
     $filesize = @filesize($upload_path . $_FILES[$fileElementName]['name'][$i]);
     $filetype = $_FILES[$fileElementName]['type'][$i];
     $table_name = CUtils::_postVar('table_name');
     $record_id = CUtils::_postVar('record_id', true, 0);
     $filewidth = 0;
     $fileheight = 0;
     if (is_array($file_info = @GetImageSize($GLOBALS['PRJ_DIR'] . $fileref))) {
         $filewidth = $file_info[0];
         $fileheight = $file_info[1];
     }
     $sql = "INSERT INTO system_files(name,mimetype,file,width,height,filesize,table_name,record_id,credate) " . " VALUES('{$filename}','{$filetype}','{$fileref}',{$filewidth},{$fileheight},'{$filesize}','{$table_name}','{$record_id}',NOW())";
     $GLOBALS['db']->execQuery('addfile', $sql);
     //$msg .= $sql;