/** * @return string */ public function getRename() { $old_name = Input::get('file'); $new_name = trim(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 (Config::get('lfm.alphanumeric_directory') && preg_match('/[^\\w-]/i', $new_name)) { return Lang::get('laravel-filemanager::lfm.error-folder-alnum'); } elseif (File::exists($new_file)) { return Lang::get('laravel-filemanager::lfm.error-rename'); } if (File::isDirectory($old_file)) { File::move($old_file, $new_file); Event::fire(new FolderWasRenamed($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); } Event::fire(new ImageWasRenamed($old_file, $new_file)); 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); }
/** * Upload an image/file and (for images) create thumbnail * * @param UploadRequest $request * @return string */ public function upload() { try { $res = $this->uploadValidator(); if (true !== $res) { return Lang::get('laravel-filemanager::lfm.error-invalid'); } } catch (\Exception $e) { return $e->getMessage(); } $file = Input::file('upload'); $new_filename = $this->getNewName($file); $dest_path = parent::getPath('directory'); if (File::exists($dest_path . $new_filename)) { return Lang::get('laravel-filemanager::lfm.error-file-exist'); } $file->move($dest_path, $new_filename); if ('Images' === $this->file_type) { $this->makeThumb($dest_path, $new_filename); } Event::fire(new ImageWasUploaded(realpath($dest_path . '/' . $new_filename))); // upload via ckeditor 'Upload' tab if (!Input::has('show_list')) { return $this->useFile($new_filename); } return 'OK'; }
/** * @return string */ public function getRename() { $old_name = Input::get('file'); $new_name = Input::get('new_name'); $file_path = parent::getPath(); $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 (Session::get('lfm_type') == 'Images') { File::move($thumb_path . $old_name, $thumb_path . $new_name); } return 'OK'; }
/** * Get the images to load for a selected folder * * @return mixed */ public function getItems() { $type = Input::get('type'); $view = $this->getView(); $path = parent::getPath(); $files = File::files($path); $file_info = $this->getFileInfos($files, $type); $directories = parent::getDirectories($path); $thumb_url = parent::getUrl('thumb'); return view($view)->with(compact('type', 'file_info', 'directories', 'thumb_url')); }
/** * 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'); // crop image $tmp_img = Image::make(public_path() . $image); $tmp_img->crop($dataWidth, $dataHeight, $dataX, $dataY)->save(public_path() . $image); // make new thumbnail $thumb_img = Image::make(public_path() . $image); $thumb_img->fit(200, 200)->save(parent::getPath('thumb') . parent::getFileName($image)['short']); }
/** * Add a new folder * * @return mixed */ public function getAddfolder() { $folder_name = Input::get('name'); $path = parent::getPath() . $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'); } } }
/** * Add a new folder * * @return mixed */ public function getAddfolder() { $folder_name = trim(Input::get('name')); $path = parent::getPath('directory') . $folder_name; if (empty($folder_name)) { return Lang::get('laravel-filemanager::lfm.error-folder-name'); } elseif (File::exists($path)) { return Lang::get('laravel-filemanager::lfm.error-folder-exist'); } elseif (Config::get('lfm.alphanumeric_directory') && preg_match('/[^\\w-]/i', $folder_name)) { return Lang::get('laravel-filemanager::lfm.error-folder-alnum'); } else { File::makeDirectory($path, $mode = 0777, true, true); return 'OK'; } }
/** * Upload an image/file and (for images) create thumbnail * * @param UploadRequest $request * @return string */ public function upload() { if (!Input::hasFile('upload')) { return Lang::get('laravel-filemanager::lfm.error-file-empty'); } $file = Input::file('upload'); $new_filename = $this->getNewName($file); $dest_path = parent::getPath(); if (File::exists($dest_path . $new_filename)) { return Lang::get('laravel-filemanager::lfm.error-file-exist'); } $file->move($dest_path, $new_filename); if (Session::get('lfm_type') == 'Images') { $this->makeThumb($dest_path, $new_filename); } // upload via ckeditor 'Upload' tab if (!Input::has('show_list')) { return $this->useFile($new_filename); } return 'OK'; }
/** * Delete image and associated thumbnail * * @return mixed */ public function getDelete() { $name_to_delete = Input::get('items'); $file_path = parent::getPath(); $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); if (Session::get('lfm_type') == 'Images') { File::delete($thumb_to_delete); } return 'OK'; }
/** * Download a file * * @return mixed */ public function getDownload() { return Response::download(parent::getPath('directory') . Input::get('file')); }