/** * @return string */ public function getRename() { $old_name = Input::get('file'); $new_name = Input::get('new_name'); $file_path = parent::getPath('directory'); $thumb_path = parent::getPath('thumb'); $old_file = $file_path . $old_name; if (!File::isDirectory($old_file)) { $extension = File::extension($old_file); $new_name = str_replace('.' . $extension, '', $new_name) . '.' . $extension; } $new_file = $file_path . $new_name; if (File::exists($new_file)) { return Lang::get('laravel-filemanager::lfm.error-rename'); } if (File::isDirectory($old_file)) { File::move($old_file, $new_file); return 'OK'; } File::move($old_file, $new_file); if ('Images' === $this->file_type) { File::move($thumb_path . $old_name, $thumb_path . $new_name); } return 'OK'; }
/** * Dipsplay image for resizing * * @return mixed */ public function getResize() { $ratio = 1.0; $image = Input::get('img'); $path_to_image = parent::getPath('directory') . $image; $original_width = Image::make($path_to_image)->width(); $original_height = Image::make($path_to_image)->height(); $scaled = false; if ($original_width > 600) { $ratio = 600 / $original_width; $width = $original_width * $ratio; $height = $original_height * $ratio; $scaled = true; } else { $width = $original_width; $height = $original_height; } if ($height > 400) { $ratio = 400 / $original_height; $width = $original_width * $ratio; $height = $original_height * $ratio; $scaled = true; } return View::make('laravel-filemanager::resize')->with('img', parent::getUrl('directory') . $image)->with('height', number_format($height, 0))->with('width', $width)->with('original_height', $original_height)->with('original_width', $original_width)->with('scaled', $scaled)->with('ratio', $ratio); }
/** * Get the images to load for a selected folder * * @return mixed */ public function getItems() { $type = Input::get('type'); $view = $this->getView($type); $path = parent::getPath(); $options = Config::get('lfm.options'); $files = File::files($path); $file_info = $this->getFileInfos($files, $type); $directories = parent::getDirectories($path); $thumb_url = parent::getUrl('thumb'); return view($view)->with(compact('files', 'file_info', 'directories', 'thumb_url', 'options')); }
/** * Add a new folder * * @return mixed */ public function getAddfolder() { $folder_name = Input::get('name'); $path = parent::getPath('directory') . $folder_name; if (!File::exists($path)) { File::makeDirectory($path, $mode = 0777, true, true); return 'OK'; } else { if (empty($folder_name)) { return Lang::get('laravel-filemanager::lfm.error-folder-name'); } else { return Lang::get('laravel-filemanager::lfm.error-folder-exist'); } } }
/** * Crop the image (called via ajax) */ public function getCropimage() { $image = Input::get('img'); $dataX = Input::get('dataX'); $dataY = Input::get('dataY'); $dataHeight = Input::get('dataHeight'); $dataWidth = Input::get('dataWidth'); $image = parent::getTruePath($image); // crop image $tmp_img = Image::make(base_path($image)); $tmp_img->crop($dataWidth, $dataHeight, $dataX, $dataY)->save(base_path($image)); // make new thumbnail $thumb_img = Image::make(base_path($image)); $thumb_img->fit(200, 200)->save(parent::getPath('thumb') . parent::getFileName($image)['short']); }
/** * Delete image and associated thumbnail * * @return mixed */ public function getDelete() { $name_to_delete = Input::get('items'); $file_path = parent::getPath('directory'); $file_to_delete = $file_path . $name_to_delete; $thumb_to_delete = parent::getPath('thumb') . $name_to_delete; if (!File::exists($file_to_delete)) { return $file_to_delete . ' not found!'; } if (File::isDirectory($file_to_delete)) { if (sizeof(File::files($file_to_delete)) != 0) { return Lang::get('laravel-filemanager::lfm.error-delete'); } File::deleteDirectory($file_to_delete); return 'OK'; } File::delete($file_to_delete); Event::fire(new ImageWasDeleted($file_to_delete)); if ('Images' === $this->file_type) { File::delete($thumb_to_delete); } return 'OK'; }
/** * Retrieve a name for the file * * @param $file * @return mixed|string */ private function getNewName($file) { $dest_path = parent::getPath('directory'); $new_filename = $this->existingFile($dest_path, $file); return $new_filename; }
/** * Download a file * * @return mixed */ public function getDownload() { return Response::download(parent::getPath('directory') . Input::get('file')); }