Esempio n. 1
0
 public function beforeDelete()
 {
     foreach ($this->photo as $value) {
         $item = SiteImage::FindByPk($value->Pk);
         $this->deleteImage($item);
         $item->delete();
     }
     return parent::beforeDelete();
 }
Esempio n. 2
0
 public function actionAploadImg()
 {
     $realUploadPath = \T4\Fs\Helpers::getRealPath($this->app->request->post->path);
     if (!is_dir($realUploadPath)) {
         try {
             \T4\Fs\Helpers::mkDir($realUploadPath);
         } catch (\T4\Fs\Exception $e) {
             throw new Exception($e->getMessage());
         }
     }
     // Helpers::mkDir(ROOT_PATH_PUBLIC . DS .'/images/pages');
     $uploaddir = $realUploadPath;
     $file = $this->app->request->post->value;
     $name = $this->app->request->post->name;
     // Получаем расширение файла
     $getMime = explode('.', $name);
     $mime = end($getMime);
     // Выделим данные
     $data = explode(',', $file);
     // Декодируем данные, закодированные алгоритмом MIME base64
     $encodedData = str_replace(' ', '+', $data[1]);
     $decodedData = base64_decode($encodedData);
     var_dump($decodedData);
     var_dump($uploaddir . $name);
     // Создаем изображение на сервере
     if (file_put_contents($uploaddir . $name, $decodedData)) {
         echo $name . ":загружен успешно";
     } else {
         // Показать сообщение об ошибке, если что-то пойдет не так.
         echo "Что-то пошло не так. Убедитесь, что файл не поврежден!";
     }
     //$lin='__'.lcfirst($this->app->request->post->class).'_id';
     $item = new SiteImage();
     $subclass = $this->app->request->post->subclass;
     $namefield = $this->app->request->post->namefield;
     $item->{$namefield} = $this->app->request->post->path . $name;
     $item->published = date('Y-m-d H:i:s', time());
     $item->{$subclass} = $this->app->request->post->id;
     $item->save();
     die;
     //$this->redirect('admin/rubrics?id='.$this->app->request->post->pageid);
 }
Esempio n. 3
0
 public function beforeDelete()
 {
     foreach ($this->photo as $value) {
         $item = SiteImage::FindByPk($value->Pk);
         $this->deleteImage($item);
         $item->delete();
     }
     $tmp = new \SplFileInfo(ROOT_PATH_PUBLIC . $item->image);
     rmdir($tmp->getPath());
     return parent::beforeDelete();
 }
Esempio n. 4
0
 public function actionSaveImage()
 {
     $item = SiteImage::FindByPk($this->app->request->post->id);
     $item->title = $this->app->request->post->title;
     $item->save();
 }