public function __construct() { parent::__construct(); /** * This can cause minor errors (eg if a user sent a file that is not a video). * So we hide the errors if we are not in development mode. */ if (!isDebug()) { error_reporting(0); } // Resizing and saving the video album thumbnail $oPicture = new Image($_FILES['album']['tmp_name']); if (!$oPicture->validate()) { \PFBC\Form::setError('form_video_album', Form::wrongImgFileTypeMsg()); } else { $iApproved = DbConfig::getSetting('videoManualApproval') == 0 ? '1' : '0'; $sFileName = Various::genRnd($oPicture->getFileName(), 1) . '-thumb.' . $oPicture->getExt(); (new VideoModel())->addAlbum($this->session->get('member_id'), $this->httpRequest->post('name'), $this->httpRequest->post('description'), $sFileName, $this->dateTime->get()->dateTime('Y-m-d H:i:s'), $iApproved); $iLastAlbumId = (int) Db::getInstance()->lastInsertId(); $oPicture->square(200); /* Set watermark text on thumbnail */ $sWatermarkText = DbConfig::getSetting('watermarkTextImage'); $iSizeWatermarkText = DbConfig::getSetting('sizeWatermarkTextImage'); $oPicture->watermarkText($sWatermarkText, $iSizeWatermarkText); $sPath = PH7_PATH_PUBLIC_DATA_SYS_MOD . 'video/file/' . $this->session->get('member_username') . PH7_DS . $iLastAlbumId . PH7_DS; $this->file->createDir($sPath); $oPicture->save($sPath . $sFileName); /* Clean VideoModel Cache */ (new Framework\Cache\Cache())->start(VideoModel::CACHE_GROUP, null, null)->clear(); HeaderUrl::redirect(Uri::get('video', 'main', 'addvideo', $iLastAlbumId)); } }
public function __construct() { parent::__construct(); // Thumbnail $oImg = new Image($_FILES['thumb']['tmp_name']); if (!$oImg->validate()) { \PFBC\Form::setError('form_game', Form::wrongImgFileTypeMsg()); return; // Stop execution of the method. } $sThumbFile = Various::genRnd($oImg->getFileName(), 30) . $oImg->getExt(); $sThumbDir = PH7_PATH_PUBLIC_DATA_SYS_MOD . 'game/img/thumb/'; $oImg->square(60); $oImg->save($sThumbDir . $sThumbFile); unset($oImg); // Game $sGameFile = Various::genRnd($_FILES['file']['name'], 30) . PH7_DOT . $this->file->getFileExt($_FILES['file']['name']); $sGameDir = PH7_PATH_PUBLIC_DATA_SYS_MOD . 'game/file/'; // If the folders is not created (games not installed), yet we will create. $this->file->createDir(array($sThumbDir, $sGameDir)); if (!@move_uploaded_file($_FILES['file']['tmp_name'], $sGameDir . $sGameFile)) { \PFBC\Form::setError('form_game', t('Impossible to upload the game. If you are the administrator, please check if the folder of games data has the write permission (CHMOD 755).')); } else { $aData = ['category_id' => $this->httpRequest->post('category_id', 'int'), 'name' => $this->httpRequest->post('name'), 'title' => $this->httpRequest->post('title'), 'description' => $this->httpRequest->post('description'), 'keywords' => $this->httpRequest->post('keywords'), 'thumb' => $sThumbFile, 'file' => $sGameFile]; (new GameModel())->add($aData); /* Clean GameModel Cache */ (new Framework\Cache\Cache())->start(GameModel::CACHE_GROUP, null, null)->clear(); HeaderUrl::redirect(Uri::get('game', 'main', 'game', $aData['title'] . ',' . Db::getInstance()->lastInsertId()), t('The game was added successfully!')); } }
/** * 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); } }
/** * 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); } }