Inheritance: extends app\http\controllers\Controller
 /**
  * @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);
 }
Example #3
0
 /**
  * @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';
 }
 private function getFileInfos($files, $type = 'Images')
 {
     $file_info = [];
     foreach ($files as $key => $file) {
         $file_name = parent::getFileName($file)['short'];
         $file_created = filemtime($file);
         $file_size = number_format(File::size($file) / 1024, 2, ".", "");
         if ($file_size > 1024) {
             $file_size = number_format($file_size / 1024, 2, ".", "") . " Mb";
         } else {
             $file_size = $file_size . " Kb";
         }
         if ($type === 'Images') {
             $file_type = File::mimeType($file);
             $icon = '';
         } else {
             $extension = strtolower(File::extension($file_name));
             $icon_array = Config::get('lfm.file_icon_array');
             $type_array = Config::get('lfm.file_type_array');
             if (array_key_exists($extension, $icon_array)) {
                 $icon = $icon_array[$extension];
                 $file_type = $type_array[$extension];
             } else {
                 $icon = "fa-file";
                 $file_type = "File";
             }
         }
         $file_info[$key] = ['name' => $file_name, 'size' => $file_size, 'created' => $file_created, 'type' => $file_type, 'icon' => $icon];
     }
     return $file_info;
 }
 /**
  * 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';
     }
 }
Example #8
0
 /**
  * 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'));
 }
 private function useFile($new_filename)
 {
     $file = parent::getUrl('directory') . $new_filename;
     return "<script type='text/javascript'>\n\n        function getUrlParam(paramName) {\n            var reParam = new RegExp('(?:[\\?&]|&)' + paramName + '=([^&]+)', 'i');\n            var match = window.location.search.match(reParam);\n            return ( match && match.length > 1 ) ? match[1] : null;\n        }\n\n        var funcNum = getUrlParam('CKEditorFuncNum');\n\n        var par = window.parent,\n            op = window.opener,\n            o = (par && par.CKEDITOR) ? par : ((op && op.CKEDITOR) ? op : false);\n\n        if (op) window.close();\n        if (o !== false) o.CKEDITOR.tools.callFunction(funcNum, '{$file}');\n        </script>";
 }