Example #1
0
 /**
  * Sets the Blog Thumbnail.
  *
  * @param object $oPost
  * @param \PH7\Framework\File\File $oFile
  * @return void
  */
 public function setThumb($oPost, Framework\File\File $oFile)
 {
     if (!empty($_FILES['thumb']['tmp_name'])) {
         $oImage = new Framework\Image\Image($_FILES['thumb']['tmp_name']);
         if (!$oImage->validate()) {
             \PFBC\Form::setError('form_blog', Form::wrongImgFileTypeMsg());
         } else {
             /**
              * The method deleteFile first test if the file exists, if so it delete the file.
              */
             $sPathName = PH7_PATH_PUBLIC_DATA_SYS_MOD . 'blog/' . PH7_IMG . $oPost->blogId;
             $oFile->deleteFile($sPathName);
             // It erases the old thumbnail
             $oFile->createDir($sPathName);
             $oImage->square(100);
             $oImage->save($sPathName . '/thumb.png');
         }
         unset($oImage);
     }
 }
Example #2
0
 /**
  * Sets the Note Thumbnail.
  *
  * @param object $oPost
  * @param \PH7\NoteModel $oNoteModel
  * @param \PH7\Framework\File\File $oFile
  * @return void
  */
 public function setThumb($oPost, NoteModel $oNoteModel, Framework\File\File $oFile)
 {
     if (!empty($_FILES['thumb']['tmp_name'])) {
         $oImage = new Framework\Image\Image($_FILES['thumb']['tmp_name']);
         if (!$oImage->validate()) {
             \PFBC\Form::setError('form_note', Form::wrongImgFileTypeMsg());
         } else {
             /**
              * The method deleteFile first test if the file exists, if so it delete the file.
              */
             $sPathName = PH7_PATH_PUBLIC_DATA_SYS_MOD . 'note/' . PH7_IMG . $oPost->username . PH7_SH;
             $oFile->deleteFile($sPathName);
             // It erases the old thumbnail
             $oFile->createDir($sPathName);
             $sFileName = Various::genRnd($oImage->getFileName(), 20) . PH7_DOT . $oImage->getExt();
             $oImage->square(100);
             $oImage->save($sPathName . $sFileName);
             $oNoteModel->updatePost('thumb', $sFileName, $oPost->noteId, $oPost->profileId);
         }
         unset($oImage);
     }
 }