diff --git a/docs/2.1/customization.md b/docs/2.1/customization.md index a5d29e0..ad585b4 100644 --- a/docs/2.1/customization.md +++ b/docs/2.1/customization.md @@ -4,13 +4,22 @@ You can resolve the upload file name creating your own class and setting in `config/filemanager.php` -These class should extends `Infinety\Filemanager\Http\Services\AbstractNamingStrategy`. +These classes should extend `Infinety\Filemanager\Http\Services\AbstractNamingStrategy`. +Per default, a random text of 7 characters will be added, if the file already exists. -Default class get the filename of uploaded file and check if exists. If exists add a random text of 7 characters. +You can also use the "Replace Strategy" to replace a file when it has the same name -You can create your custom class to customize the uploaded name. +```php + // config/filemanager.php + + 'naming' => \Infinety\Filemanager\Http\Services\ReplaceFileNamingStrategy::class, +``` + + +You can easily create your own custom class to customize the uploaded name. +This is the implementation of the Default Class: ```php namespace Infinety\Filemanager\Http\Services; diff --git a/src/Http/Services/ReplaceFileNamingStrategy.php b/src/Http/Services/ReplaceFileNamingStrategy.php new file mode 100644 index 0000000..a37fa6b --- /dev/null +++ b/src/Http/Services/ReplaceFileNamingStrategy.php @@ -0,0 +1,19 @@ +getClientOriginalName(); + + if ($this->storage->exists($currentFolder.'/'.$filename)) { + $this->storage->delete($currentFolder.'/'.$filename); + } + + return $filename; + } +}