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: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ In your model `initialize()`:
$this->addBehavior('Xety/Cake3Upload.Upload', [
'fields' => [
'avatar' => [
'path' => 'upload/avatar/:id/:md5'
'path' => 'upload/avatar/:model/:id/:md5'
]
]
]
Expand All @@ -57,6 +57,7 @@ If specified in your Entity, add the suffixed field (e.g. `avatar_file`) to the

### Identifiers
* **:id** Id of the Entity (It can be the user Id if you are using this for the users table for example)
* **:model** Table name of the Entity
* **:md5** A random and unique identifier with 32 characters. i.e : *bbebb3c3c5e76a46c3dca92c9395ee65*
* **:y** Based on the current year. i.e : *2014*
* **:m** Based on the current month. i.e : *09*
Expand All @@ -70,7 +71,7 @@ If specified in your Entity, add the suffixed field (e.g. `avatar_file`) to the
$this->addBehavior('Upload', [
'fields' => [
'avatar' => [
'path' => 'upload/avatar/:id/:md5'
'path' => 'upload/avatar/:model/:id/:md5'
]
],
'suffix' => '_anotherName'
Expand All @@ -88,7 +89,7 @@ If specified in your Entity, add the suffixed field (e.g. `avatar_file`) to the
$this->addBehavior('Upload', [
'fields' => [
'avatar' => [
'path' => 'upload/avatar/:id/:md5',
'path' => 'upload/avatar/:model/:id/:md5',
'overwrite' => false
]
]
Expand All @@ -104,7 +105,7 @@ If specified in your Entity, add the suffixed field (e.g. `avatar_file`) to the
$this->addBehavior('Upload', [
'fields' => [
'avatar' => [
'path' => 'upload/avatar/:id/:md5',
'path' => 'upload/avatar/:model/:id/:md5',
'overwrite' => true,
'defaultFile' => 'default_avatar.png'
]
Expand All @@ -121,7 +122,7 @@ If specified in your Entity, add the suffixed field (e.g. `avatar_file`) to the
$this->addBehavior('Upload', [
'fields' => [
'avatar' => [
'path' => 'upload/avatar/:id/:md5',
'path' => 'upload/avatar/:model/:id/:md5',
'prefix' => '../'
]
]
Expand All @@ -142,7 +143,7 @@ If specified in your Entity, add the suffixed field (e.g. `avatar_file`) to the
$this->addBehavior('Upload', [
'fields' => [
'avatar' => [
'path' => 'upload/avatar/:id/:md5',
'path' => 'upload/avatar/:model/:id/:md5',
'prefix' => '../'
]
]
Expand All @@ -151,7 +152,7 @@ If specified in your Entity, add the suffixed field (e.g. `avatar_file`) to the

// In a view, with the Html Helper:
<?= $this->Html->image($User->avatar) ?>
// Output : <img src="/img/../upload/avatar/1/bbebb3c3c5e76a46c3dca92c9395ee65.png" alt="">
// Output : <img src="/img/../upload/avatar/[tablename]/1/bbebb3c3c5e76a46c3dca92c9395ee65.png" alt="">
```

## Contribute
Expand Down
1 change: 1 addition & 0 deletions src/Model/Behavior/UploadBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ protected function _getUploadPath(Entity $entity, $path = false, $extension = fa

$identifiers = [
':id' => $entity->id,
':model' => strtolower($entity->source()),
':md5' => md5(rand() . uniqid() . time()),
':y' => date('Y'),
':m' => date('m')
Expand Down