/** * Generate thumb file for image. * The thumb file has same type with original file. However it have small resolution and name has thumb_ prefix * @param string $localPath * @return boolean */ public function generateThumb($localPath, $serverPath) { $maxWidth = MAX_WIDTH_THUMB; $maxHeight = MAX_HEIGHT_THUMB; $thumbServerPath = dirname($serverPath) . DS . "thumb_" . DS . basename($serverPath); $thumbLocalPath = $localPath . "_thumb"; $resizeStatus = $this->resizeImage($localPath, $thumbLocalPath, $maxWidth, $maxHeight); if ($resizeStatus) { $uploadStatus = $this->fileSystem->uploadFile($thumbLocalPath, $thumbServerPath); if ($uploadStatus) { return true; } } return false; }
/** * Input file for media * @param File Object $fileObj File upload by user * @return boolean true if all ok. Otherwise, false */ public function initFile($fileObj) { $fileExt = $fileObj->getExtension(); $filesAccept = $this->constants->mediaAcceptFilesExt(); if (!in_array($fileExt, $filesAccept)) { $this->error[] = $this->constants->mediaFileNotAccept(); return false; } $userName = $this->auth->getUsername(); $year = date("Y"); $month = date("M"); $fileName = $fileObj->getName(); $serverPath = $userName . "/" . $year . "/" . $month . "/" . $fileName; $localPath = "/tmp/" . $fileObj->getTempName(); if ($this->fileSystem->uploadFile($localPath, $serverPath)) { return true; } $this->error[] = $this->constants->mediaUploadError(); return false; }