Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions docs/2.1/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions src/Http/Services/ReplaceFileNamingStrategy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Infinety\Filemanager\Http\Services;

use Illuminate\Http\UploadedFile;

class ReplaceFileNamingStrategy extends AbstractNamingStrategy
{
public function name(string $currentFolder, UploadedFile $file): string
{
$filename = $file->getClientOriginalName();

if ($this->storage->exists($currentFolder.'/'.$filename)) {
$this->storage->delete($currentFolder.'/'.$filename);
}

return $filename;
}
}