1. Go to this page and download the library: Download 3xw/attachment library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
'upload' => [
'maxsize' => 30, // 30MB
'types' =>['image/jpeg','embed/soundcloud',...], // mime types and embed/:service for embed stuff
'atags' => [], // atags are use to store attachemnts with
'relation' => 'belongsToMany', // model relation
'profile' => 'default', // profile to use (where you store files)
'visibility' => 'public', // public or private
'speech' => false, // french goody
'restrictions' => [] // or Attachment\View\Helper\AttachmentHelper::TAG_RESTRICTED
],
AttachmentHelper::TAG_RESTRICTED // enforce attachments to associted with given tags in save and retieve with a AND strategy
AttachmentHelper::TAG_OR_RESTRICTED // enforce attachments to associted with given tags in save and retieve with a OR strategy
AttachmentHelper::types_restricted // enforce attachments to saved and retrieve with a OR strategy according given mime types
namespace App\Listener;
use Attachment\Listener\BaseListener;
use Cake\Event\Event;
class ExtranetMoveFileListener extends BaseListener
{
// $event->getSubject() returns an object with minimum a request variable
// all model events are wrapped on top of:
// https://crud.readthedocs.io/en/latest/events.html#crud-beforesave
public function respond(Event $event)
{
}
}
'thumbnails' => [
'driver' => 'Imagick', // or Imagick if installed,
'widths' => [600, 1200],
'heights' => [],
'aligns' => [], // or some of following [0,1,2,3,4,5,6,7,8] with 0 center, 1 top, 4 left, 5 right top corner, 8 left top corner ....
'crops' => ['4:3','16:9']
]
public function index()
{
$this->paginate = [
'contain' => ['Attachments' /* => ['sort' => 'order'] */ ] // if HABTM with an order field
];
$posts = $this->paginate($this->Posts);
$this->set(compact('posts'));
$this->set('_serialize', ['posts']);
}
public function initialize()
{
$this->loadHelper('Attachment.Attachment');
}
<!-- Attachment -->
<?= $this->Attachment->input('Attachments', // if Attachments => HABTM else if !Attachments => belongsTo
[
'label' => 'Image',
'types' =>['image/jpeg','image/png'],
'atags' => ['Restricted Tag 1', 'Restricted Tag 2'],
'profile' => 's3', // optional as it was set in config/attachment.php
'cols' => 'col-xs-6 col-md-6 col-lg-4', // optional as it was set in config/attachment.php,
'maxquantity' => -1,
'restrictions' => [
Attachment\View\Helper\AttachmentHelper::TAG_RESTRICTED,
Attachment\View\Helper\AttachmentHelper::TYPES_RESTRICTED
],
'attachments' => [] // array of exisiting Attachment entities ( HABTM ) or [entity] ( belongsTo )
]
)
<!-- Attachment -->
<?= $this->Attachment->input('Attachments', // if Attachments => HABTM else if !Attachments => belongsTo
[
'label' => 'Image',
'types' =>['image/jpeg','image/png'],
'atags' => ['Restricted Tag 1', 'Restricted Tag 2'],
'profile' => 's3', // optional as it was set in config/attachment.php
'cols' => 'col-xs-6 col-md-6 col-lg-4', // optional as it was set in config/attachment.php,
'maxquantity' => -1,
'restrictions' => [
Attachment\View\Helper\AttachmentHelper::TAG_RESTRICTED,
Attachment\View\Helper\AttachmentHelper::TYPES_RESTRICTED
],
'attachments' => $posts->attachments // array of exisiting Attachment entities ( HABTM ) or entity ( belongsTo )
]
)
<!-- Attachments element -->
<?= $this->Attachment->buildIndex([
'actions' => ['add','edit','delete','view','download'],
'types' =>['image/jpeg','image/png','embed/youtube','embed/vimeo'],
'atags' => ['Restricted Tag 1', 'Restricted Tag 2'],
'listStyle' => true,
'profile' => 's3', // optional as it was set in config/attachment.php
'restrictions' => [
Attachment\View\Helper\AttachmentHelper::TAG_RESTRICTED,
Attachment\View\Helper\AttachmentHelper::TYPES_RESTRICTED
]
])