grandfelix / woodyattachments
WoodyAttachments 文件上传插件,适用于 CakePHP 3
dev-master
2023-09-06 05:55 UTC
Requires
- php: >=5.4.16
- cakephp/cakephp: ~3.0
- imagine/imagine: *
Requires (Dev)
This package is not auto-updated.
Last update: 2024-09-14 17:53:42 UTC
README
CakePHP 3 文件上传插件。
要求
CakePHP 3 PHP > 5.4.16
使用 imagine/imagine 进行图像处理
安装
composer require GrandFelix/WoodyAttachments
在 shell 中运行 composer update
运行迁移
bin/cake migrations migrate --plugin WoodyAttachments
如何使用它
将此添加到您的 Table 文件中
$this->addBehavior('WoodyAttachments.Upload', [ 'fields' => [ 'images' => [ 'allowedFileTypes' => ['image/jpeg', 'image/png'], 'fileSize' => '2MB', 'numberOfFiles' => 20, 'operations' => [ // remove all this if you don't want to make any file operations 'thumb' => [ // this wil be folder name uploads folder 'thumbnail' => [ 'w' => 270, 'h' => 198 ], 'effects' => ['negative'] // add Imagine effects ], 'mid' => [ // this wil be folder name uploads folder 'widen' => [ 'size' => 600 ], 'effects' => ['grayscale'], 'rotate' => ['degrees' => 90] ], ] ], 'pdf' => [ 'allowedFileTypes' => ['application/pdf'], 'fileSize' => '2MB', ] ] ]);
目前仅对图像有文件操作...
对于多文件上传,将此添加到您的视图文件中
echo $this->Form->input('images[]', [ 'multiple' => true, 'label' => 'Pictures', 'type' => 'file' ]);
或此用于单文件上传
echo $this->Form->input('pdf', [ 'label' => 'PDF file', 'type' => 'file' ]);
表单输入必须与加载行为时的配置中的名称相同。所以在本例中是图像和 pdf
别忘了在 $this->Form->create('ModelName', ['type' => 'file']) 中添加 ['type' => 'file']
在 config/bootstrap.php 中更改主上传路径
其他
- 文件保存在 webroot/{你的配置文件中的文件上传文件夹}/{Year}/{Month}/{Model}/*
- 当你删除项时,文件也会被删除...
待办事项
- 由于创建速度非常快,因此进行了大量的代码改进
- 将文件操作移到其他位置..
- 创建助手以自动渲染文件
- 管理控制器
- 可配置的文件保存路径
- 识别文件类型,并为此文件类型使用文件操作
- ...