wsw / simple-upload
简单上传系统
1.0.3
2017-12-11 10:52 UTC
Requires
- league/flysystem: ^1.0
Requires (Dev)
- fzaninotto/faker: ~1.4
- phpunit/phpunit: ~5.7
- rdehnhardt/var-dumper: ^1.1
- squizlabs/php_codesniffer: ^2.3
This package is auto-updated.
Last update: 2024-08-29 04:48:42 UTC
README
PHP中的简单上传系统,兼容AWS S3、Dropbox、Azure等。
负责简化文件上传的组件。使用它,可以执行本地上传以及以下服务:Dropbox、AWS S3、Azure、SFTP等。完整的列表请查看这里。
安装
通过Composer
composer require wsw/simple-upload
使用方法
基本使用
<?php use League\Flysystem\Adapter\Local; use WSW\SimpleUpload\Services\SimpleUpload; try { $adapter = new Local('/home/files'); $file = SimpleUpload::create($_FILES['file'], $adapter)->send(); } catch (\Exception $e) { echo $e->getMessage(); }
高级使用
<?php use League\Flysystem\Adapter\Local; use WSW\SimpleUpload\Services\SimpleUpload; try { $adapter = new Local('/home/files'); $upload = SimpleUpload::create($_FILES['file'], $adapter); // Optional Methods //Create a new directory from the root directory defined on the adapter. $upload->setPath('newDir'); // Ex:/home/files/newDir/ // Define a new file name $upload->setName('newName'); // Ex: newName.csv // Defines which file extensions the upload will allow $upload->setAllowedExtensions(['csv', 'txt']); $file = $upload->send(); } catch (\Exception $e) { echo $e->getMessage(); }
结果
<?php // Returns the size of the file in KB echo $file->getSize(); // 94762 // Returns the file type echo $file->getMimetype(); // text/plain // Returns instance of DateTime for date and time of creation echo $file->getTimestamp(); // \DateTime // Absolute file path echo $file->getPath(); // /home/files/file.txt // Directory where the file is located echo $file->getFilePath(); // /home/files/ // Filename with extension echo $file->getFileName(); // file.txt // Filename without extension echo $file->getName(); // file // File extension echo $file->getExtension(); // txt
测试
$ composer test
安全性
如果您发现任何与安全性相关的问题,请通过电子邮件 ronaldo@whera.com.br 联系我们,而不是使用问题跟踪器。
致谢
许可证
MIT许可证(MIT)。更多信息请参阅许可证文件。