public static function saveMedia($id_user, $id_album, $name, $format, $ext = null)
 {
     // check if the user has the edit access on the album
     $access = UsersAlbumsAccess::getAlbumAccess($id_user, $id_album);
     if ($access && $access->edit_access) {
         if (isset(self::$_image_formats[$format])) {
             $media = new Medias();
             $media->name = $name;
             $media->format = $ext == null ? self::$_image_formats[$format] : $ext;
             $media->id_album = $id_album;
             // if($media->save() == false) {
             // 	foreach ($media->getMessages() as $message) {
             //         echo $message, "\n";
             //     }
             // }
             return $media->save();
         }
     }
     return false;
 }
Exemple #2
0
 public function actionImageupload()
 {
     $model = new Medias('create');
     $uploadedFile = CUploadedFile::getInstanceByName('uploadedfile');
     if ($uploadedFile != null) {
         $model->real_name = $uploadedFile;
         $fileName = $model->getImageName($uploadedFile);
         $model->url = $fileName;
         $model->type = 'image-upload';
         $model->title = substr($fileName, 25);
     } else {
         return;
     }
     if ($model->save()) {
         $model->saveImage($fileName, $uploadedFile);
         $this->layout = "";
         $this->render('imageupload', array('model' => $model));
     }
 }