/**
  * 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('imgName', $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('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');
     }
     Event::fire(new ImageWasRenamed($old_file, $new_file));
     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';
 }
 /**
  * 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'));
 }
 /**
  * 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');
     $imgName = Input::get('imgName');
     $workingDir = trim(Input::get('working_dir'));
     $dataX = Input::get('dataX');
     $dataY = Input::get('dataY');
     $dataHeight = Input::get('dataHeight');
     $dataWidth = Input::get('dataWidth');
     $imagePath = $this->getImagePathForProcess($workingDir, $imgName);
     // crop image
     $tmp_img = Image::make($imagePath);
     $tmp_img->crop($dataWidth, $dataHeight, $dataX, $dataY)->save($imagePath);
     // make new thumbnail
     $thumb_img = Image::make($imagePath);
     $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';
 }
 /**
  * Download a file
  *
  * @return mixed
  */
 public function getDownload()
 {
     return Response::download(parent::getPath('directory') . Input::get('file'));
 }