fm-labs / cakephp-upload
CakePHP 的上传插件
1.4.2
2023-03-15 15:42 UTC
Requires
- php: >=7.2
- cakephp/cakephp: ^4.0
Requires (Dev)
- fm-labs/cakephp-devtools: dev-master
- phpunit/phpunit: ^8
README
适用于 CakePHP4 的简单文件上传插件
安装
$ composer require fm-labs/cakephp-upload
使用
// Example Controller class UploadController extends \Cake\Controller\Controller { public function upload() { // create Uploader instance $uploader = new \Upload\Uploader([]); // alternatively the uploader config can be loaded from a config file // (copy example config from PLUGIN/config/upload.sample.php to app/config/upload.php) //\Cake\Core\Configure::load('upload'); //$uploader = new \Upload\Uploader('default'); // process the uploaded data $uploader->upload($this->getRequest()->getData('uploadfile')); // the result is a list of uploaded files // [[ // 'name' => '/path/to/file', // 'size' => (int) 1234, // 'mime_type' => 'text/plain' // 'error' => 0 // ], [...]] $result = $uploader->getResult(); } }
// Example upload form using CakePHP FormHelper
<?= $this->Form->create(null); ?>
<?= $this->Form->input('uploadfile', ['type' => 'file']; ?>
<?= $this->Form->submit('Upload'); ?>
<?= $this->Form->end(); ?>
// Example upload form using plain html
<form method="POST" action="/url/to/upload-controller/">
<input name="uploadfile" type="file" />
<input type="submit" value="Upload" />
</form>
运行测试
$ composer run test
变更日志
[1.3]
- CakePHP 4.0 迁移
[1.2]
- CakePHP 3.8 迁移
[1.1]
- 添加了上传器选项 'saveAs'
- 重构了带有 InstanceConfigTrait 的上传器
[1.0]
- 需要 CakePHP 3.3
许可
查看 LICENSE 文件