Example #1
0
 /**
  * Сохранение поля "Файл"
  * @return void
  */
 public function save_variable_file()
 {
     if ($_POST['type'] == 1) {
         if (!empty($_FILES["attachment_img"]['name'])) {
             $extension_array = array('jpg', 'jpeg', 'gif', 'png');
             $new_name = strtolower($this->diafan->translit($_FILES["attachment_img"]['name']));
             $extension = substr(strrchr($new_name, '.'), 1);
             if (!in_array($extension, $extension_array)) {
                 throw new Exception('Не удалось загрузить файл. Возможно, закрыт доступ к папке или файл превышает максимально допустимый размер');
             }
             $new_name = substr($new_name, 0, -(strlen($extension) + 1)) . '_' . $this->diafan->id . '.' . $extension;
             $file_name = DB::query_result("SELECT file FROM {bs} WHERE id=%d LIMIT 1", $this->diafan->id);
             if (!empty($file_name)) {
                 File::delete_file(USERFILES . '/' . $this->diafan->table . '/' . $file_name);
             }
             File::upload_file($_FILES["attachment_img"]['tmp_name'], USERFILES . "/pbs/" . $new_name);
             $this->diafan->set_query("file='%s'");
             $this->diafan->set_value($new_name);
             $this->diafan->set_query("html='%s'");
             $this->diafan->set_value('');
             $this->diafan->set_query("width='%d'");
             $this->diafan->set_value('');
             $this->diafan->set_query("height='%d'");
             $this->diafan->set_value('');
         }
         $this->diafan->set_query("type=%d");
         $this->diafan->set_value(1);
         $this->diafan->set_query("alt" . _LANG . "='%s'");
         $this->diafan->set_value($_POST['alt']);
         $this->diafan->set_query("title" . _LANG . "='%s'");
         $this->diafan->set_value($_POST['title']);
     }
     if ($_POST['type'] == 2) {
         if (!empty($_FILES["attachment_swf"]['name'])) {
             $extension_array = array('swf');
             $new_name = strtolower($this->diafan->translit($_FILES["attachment_swf"]['name']));
             $extension = substr(strrchr($new_name, '.'), 1);
             if (!in_array($extension, $extension_array)) {
                 throw new Exception($this->diafan->_('Не удалось загрузить файл. Возможно, закрыт доступ к папке или файл превышает максимально допустимый размер'));
             }
             $new_name = substr($new_name, 0, -(strlen($extension) + 1)) . '_' . $this->diafan->id . '.' . $extension;
             $file_name = DB::query_result("SELECT file FROM {bs} WHERE id=%d LIMIT 1", $this->diafan->id);
             if (!empty($file_name)) {
                 File::delete_file(USERFILES . '/' . $this->diafan->table . '/' . $file_name);
             }
             File::upload_file($_FILES["attachment_swf"]['tmp_name'], USERFILES . "/" . $this->diafan->table . '/' . $new_name);
             $this->diafan->set_query("file='%s'");
             $this->diafan->set_value($new_name);
             $this->diafan->set_query("html='%s'");
             $this->diafan->set_value('');
             $this->diafan->set_query("alt" . _LANG . "='%s'");
             $this->diafan->set_value('');
             $this->diafan->set_query("title" . _LANG . "='%s'");
             $this->diafan->set_value('');
         }
         $this->diafan->set_query("type='%d'");
         $this->diafan->set_value(2);
         $this->diafan->set_query("width='%d'");
         $this->diafan->set_value($_POST['width']);
         $this->diafan->set_query("height='%d'");
         $this->diafan->set_value($_POST['height']);
     }
     if ($_POST['type'] == 3) {
         if (!empty($_POST['html'])) {
             $file_name = DB::query_result("SELECT file FROM {bs} WHERE id=%d LIMIT 1", $this->diafan->id);
             if (!empty($file_name)) {
                 File::delete_file(USERFILES . '/' . $this->diafan->table . '/' . $file_name);
             }
             $this->diafan->set_query("html='%s'");
             $this->diafan->set_value($_POST['html']);
             $this->diafan->set_query("file='%s'");
             $this->diafan->set_value('');
             $this->diafan->set_query("alt" . _LANG . "='%s'");
             $this->diafan->set_value('');
             $this->diafan->set_query("title" . _LANG . "='%s'");
             $this->diafan->set_value('');
             $this->diafan->set_query("width='%d'");
             $this->diafan->set_value('');
             $this->diafan->set_query("height='%d'");
             $this->diafan->set_value('');
         }
         $this->diafan->set_query("type='%d'");
         $this->diafan->set_value(3);
     }
 }