Closed fcamargo10 closed 7 years ago
Did you see: https://github.com/josegonzalez/cakephp-upload/blob/21cef97798d82da9c31afdb3b1a246a453271665/docs/configuration.rst? :) It says something about renaming
I see, but i don't know how to use. Can u help me ? Look my example:
$this->addBehavior('Josegonzalez/Upload.Upload', [ 'icon' => [ 'path' => 'webroot{DS}files{DS}{model}{DS}{field}{DS}', ] ]);
The upload is correct, but ... when I upload a file with the same name it is overwritten.
You need to specify the nameCallback option.
Fine. Can u give me a example ? It is a string or a function ?
It is a method which the behavior can call. It's listed in the documentation.
// In your Table class
$this->addBehavior('Josegonzalez/Upload.Upload', [
'nameCallback' => [$this, 'renameFile'],
]);
// Table method in the same table the behaviour is loaded on
public function renameFile(array $data, array $settings): string
{
$newFilename = str_replace('Example', '', $data['file']);
return $newFilename;
}
Hi, i don't know how to rename the file to save. Can you help me ?