diff --git a/composer.json b/composer.json index 028f6c2c..a545d668 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "unisharp/laravel-filemanager", + "name": "candidoalberto/laravel-filemanager", "description": "A file upload/editor intended for use with Laravel 5 to 6 and CKEditor / TinyMCE", "license": "MIT", "keywords": [ diff --git a/docs/config.md b/docs/config.md index d1a1ee5a..a90d267a 100644 --- a/docs/config.md +++ b/docs/config.md @@ -116,6 +116,24 @@ Detail options are explained here: ## Upload / Validation: +| Key | Type | Description | +|----------------------------|---------|---------------------------------------------------------------------------| +| disk (Alpha version only) | string | Correspond to `disks` section in `config/filesystems.php`. | +| rename_file | string | If true, the uploaded file will be renamed to uniqid() + file extension. | +| alphanumeric_filename | boolean | If true, non-alphanumeric file name will be replaced with `_`. | +| slug_filename | boolean | If true, use Str::slug class Laravel method generates a URL friendly | +| alphanumeric_directory | boolean | If true, non-alphanumeric folder name will be rejected. | +| should\_validate\_size | boolean | If true, the size of uploading file will be verified. | +| max\_image\_size | int | Specify max size of uploading image. | +| max\_file\_size | int | Specify max size of uploading file. | +| should\_validate\_mime | boolean | If true, the mime type of uploading file will be verified. | +| valid\_image\_mimetypes | array | Array of mime types. Available since v1.3.0 . | +| should\_create\_thumbnails | boolean | If true, thumbnails will be created for faster loading. | +| raster\_mimetypes | array | Array of mime types. Thumbnails will be created only for these mimetypes. | +| create\_folder\_mode | int | Permission setting for folders created by this package. | +| create\_file\_mode | int | Permission setting for files uploaded to this package. | +| should\_change\_file\_mode | boolean | If true, it will attempt to chmod the file after upload | +| valid\_file\_mimetypes | array | Array of mime types. Available since v1.3.0 . | ### disk * type: `string` diff --git a/src/Controllers/CropController.php b/src/Controllers/CropController.php index a78e4113..27446cc6 100644 --- a/src/Controllers/CropController.php +++ b/src/Controllers/CropController.php @@ -42,9 +42,14 @@ public function getCropimage($overWrite = true) $crop_info = request()->only('dataWidth', 'dataHeight', 'dataX', 'dataY'); // crop image - Image::make($image_path) - ->crop(...array_values($crop_info)) - ->save($crop_path); + $name = $this->helper->getNameFromPath($image_path); + + $imagefile = $this->lfm->pretty($image_path); + + $image = Image::make($imagefile->get()) + ->crop(...array_values($crop_info)); + + $this->lfm->setName($name)->storage->put($image->stream()); // make new thumbnail $this->lfm->generateThumbnail($image_name); diff --git a/src/Controllers/FolderController.php b/src/Controllers/FolderController.php index 3e5b666d..64a0cd56 100644 --- a/src/Controllers/FolderController.php +++ b/src/Controllers/FolderController.php @@ -4,7 +4,7 @@ use UniSharp\LaravelFilemanager\Events\FolderIsCreating; use UniSharp\LaravelFilemanager\Events\FolderWasCreated; - +use Illuminate\Support\Str; class FolderController extends LfmController { /** @@ -42,6 +42,8 @@ public function getAddfolder() { $folder_name = $this->helper->input('name'); + $folder_name = Str::slug($folder_name, '_'); + $new_path = $this->lfm->setName($folder_name)->path('absolute'); event(new FolderIsCreating($new_path)); @@ -51,8 +53,6 @@ public function getAddfolder() return $this->helper->error('folder-name'); } elseif ($this->lfm->setName($folder_name)->exists()) { return $this->helper->error('folder-exist'); - } elseif (config('lfm.alphanumeric_directory') && preg_match('/[^\w-]/i', $folder_name)) { - return $this->helper->error('folder-alnum'); } else { $this->lfm->setName($folder_name)->createFolder(); } diff --git a/src/Controllers/RenameController.php b/src/Controllers/RenameController.php index d8187d58..4a86bb5e 100644 --- a/src/Controllers/RenameController.php +++ b/src/Controllers/RenameController.php @@ -9,6 +9,7 @@ use UniSharp\LaravelFilemanager\Events\FileWasRenamed; use UniSharp\LaravelFilemanager\Events\ImageIsRenaming; use UniSharp\LaravelFilemanager\Events\ImageWasRenamed; +use Illuminate\Support\Str; class RenameController extends LfmController { @@ -35,13 +36,7 @@ public function getRename() } } - if ($is_directory && config('lfm.alphanumeric_directory') && preg_match('/[^\w-]/i', $new_name)) { - return parent::error('folder-alnum'); - } elseif (config('lfm.alphanumeric_filename') && preg_match('/[^.\w-]/i', $new_name)) { - return parent::error('file-alnum'); - } elseif ($this->lfm->setName($new_name)->exists()) { - return parent::error('rename'); - } + $new_name = Str::slug($new_name, '_'); if (! $is_directory) { $extension = $old_file->extension(); diff --git a/src/Controllers/ResizeController.php b/src/Controllers/ResizeController.php index 39693734..9ace12e8 100644 --- a/src/Controllers/ResizeController.php +++ b/src/Controllers/ResizeController.php @@ -18,7 +18,9 @@ public function getResize() $ratio = 1.0; $image = request('img'); - $original_image = Image::make($this->lfm->setName($image)->path('absolute')); + $imagefile = $this->lfm->pretty($this->lfm->setName($image)->path('absolute')); + + $original_image = Image::make($imagefile->get()); $original_width = $original_image->width(); $original_height = $original_image->height(); @@ -57,7 +59,15 @@ public function performResize() $image_path = $this->lfm->setName(request('img'))->path('absolute'); event(new ImageIsResizing($image_path)); - Image::make($image_path)->resize(request('dataWidth'), request('dataHeight'))->save(); + + $name = $this->helper->getNameFromPath($image_path); + + $imagefile = $this->lfm->pretty($image_path); + + $image = Image::make($imagefile->get())->resize(request('dataWidth'), request('dataHeight')); + + $this->lfm->setName($name)->storage->put($image->stream()); + event(new ImageWasResized($image_path)); return parent::$success_response; diff --git a/src/LfmPath.php b/src/LfmPath.php index 038cc9d2..b3f5e00e 100644 --- a/src/LfmPath.php +++ b/src/LfmPath.php @@ -9,6 +9,7 @@ use UniSharp\LaravelFilemanager\Events\FileWasUploaded; use UniSharp\LaravelFilemanager\Events\ImageIsUploading; use UniSharp\LaravelFilemanager\Events\ImageWasUploaded; +use Illuminate\Support\Str; use UniSharp\LaravelFilemanager\LfmUploadValidator; class LfmPath @@ -227,7 +228,15 @@ public function upload($file) event(new FileIsUploading($new_file_path)); event(new ImageIsUploading($new_file_path)); try { + $this->setName($new_file_name)->storage->save($file); + + //----- Rezise image + $original_image = $this->pretty($new_file_name); + $image = Image::make($original_image->get())->resize(800, 600,function ($constraint) { + $constraint->aspectRatio(); + }); + $this->setName($new_file_name)->storage->put($image->stream()); $this->generateThumbnail($new_file_name); } catch (\Exception $e) { @@ -274,11 +283,7 @@ private function getNewName($file) $extension = $file->getClientOriginalExtension(); - if (config('lfm.rename_file') === true) { - $new_file_name = uniqid(); - } elseif (config('lfm.alphanumeric_filename') === true) { - $new_file_name = preg_replace('/[^A-Za-z0-9\-\']/', '_', $new_file_name); - } + $new_file_name = Str::slug($new_file_name, '_'); if ($extension) { $new_file_name_with_extention = $new_file_name . '.' . $extension; diff --git a/src/config/lfm.php b/src/config/lfm.php index e8c4fd43..dc768cc5 100644 --- a/src/config/lfm.php +++ b/src/config/lfm.php @@ -100,9 +100,11 @@ 'rename_duplicates' => false, - 'alphanumeric_filename' => false, + 'slug_filename' => false, + + 'alphanumeric_directory' => false, - 'alphanumeric_directory' => false, + 'alphanumeric_filename' => false, 'should_validate_size' => false,