/** * Removes the category path * * @param $input * @return bool */ public function destroyCategory($input) { if (isset($input['category'])) { $localPath = $this->CategoryPaths->fromDot($input['category']); $serverPath = $this->CategoryPaths->serverPath($localPath); return $this->Filesystem->deleteDirectory($serverPath); } return false; }
/** * Saves the uploaded file to the media directory * * @param $input * @return bool */ public function saveUploadedFile($input) { $file = array_get($input, 'file', null); if (is_null($file)) { return false; } $originalName = $file->getClientOriginalName(); $localPath = isset($input['category']) ? $this->CategoryPaths->fromDot($input['category']) : ''; $serverPath = $this->CategoryPaths->serverPath($localPath); $newName = $this->createFile($file, $serverPath, $originalName); if ($this->Image->canMakeThumbnailFromFile($file)) { $thumbnailPath = $this->getThumbnailPath($localPath . '/' . $newName); if (!is_dir(dirname($thumbnailPath))) { mkdir(dirname($thumbnailPath), 0755, true); } $this->Image->makeThumbnailImage($serverPath . $newName, $thumbnailPath, $file->getClientMimeType()); } return $localPath . '/' . $newName; }
/** * Crop and save an image * * @param $input * @return string */ public function cropAndSaveFile($input) { $imagePath = array_get($input, 'image', null); if (is_null($imagePath)) { return false; } // lots of variables to make this code easier to read $width = $input['cropper']['width']; $height = $input['cropper']['height']; $cropWidth = $input['cropper']['w']; $cropHeight = $input['cropper']['h']; $cropX = $input['cropper']['x']; $cropY = $input['cropper']['y']; // find the paths $croppedName = $this->getNewCroppedName($imagePath, $width, $height); $localPath = isset($input['category']) ? $this->CategoryPaths->fromDot($input['category']) : ''; $serverPath = $this->CategoryPaths->serverPath($localPath); $imagePath = $serverPath . $input['image']; // resize and crop image and save it to media directory $image = $this->Images->cropAndResizeImage($imagePath, $width, $height, $cropWidth, $cropHeight, $cropX, $cropY); $this->Images->saveImage($image, $serverPath . $croppedName); return $croppedName; }