ruvents / spiral-upload
上传管理
0.1.0
2021-12-17 10:04 UTC
Requires
- php: ^8.0
- spiral/framework: ^2.8
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- league/flysystem-memory: ^2.0
- phpunit/phpunit: ^9.5.10
README
包含一些辅助工具的上传管理包。
安装
composer require ruvents/spiral-upload
然后在您的 App.php
文件中添加 UploadBootloader
use Ruvents\SpiralUpload\UploadBootloader; class App extends Kernel { protected const LOAD = [ ... UploadBootloader::class, ] }
配置
将以下代码放入文件 app/config/upload.php
<?php declare(strict_types=1); return [ 'uploadClass' => Upload::class, // Custom UploadInterface implementation class. 'urlPrefix' => 'https://foo.bar/uploads/', // Public URL to uploads. Example: // https://foo.bar/uploads/f8/some-upload.png -- full URL to upload // https://foo.bar/uploads -- URL prefix // f8/some-upload.png -- relative path to upload ];
使用
使用 UploadManager
执行与上传相关的任务
public function manageUploads(UploadManager $manager) { // Create upload from file path. $upload = $manager->create('/path/to/file.txt', 'file.txt'); // Create upload from resource. $upload = $manager->create($handle = fopen('/path/to/file.txt', 'r'), 'file.txt'); fclose($handle); // Or from UploadedFileInterface. $stream = clone $uploadedFile->getStream(); $upload = $manager->create($stream->detach(), 'file.txt'); // Get full URL of upload. $url = $manager->url($upload); // Delete stored file associated with upload. $manager->delete($upload); }