├── .github ├── FUNDING.yml └── dependabot.yml ├── .editorconfig ├── src └── QiniuStorageServiceProvider.php ├── composer.json └── README.md /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [overtrue] 2 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: composer 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | time: "21:00" 8 | open-pull-requests-limit: 10 9 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 4 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = false 10 | 11 | [*.{vue,js,scss}] 12 | charset = utf-8 13 | indent_style = space 14 | indent_size = 2 15 | end_of_line = lf 16 | insert_final_newline = true 17 | trim_trailing_whitespace = true 18 | 19 | [*.md] 20 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /src/QiniuStorageServiceProvider.php: -------------------------------------------------------------------------------- 1 | extend('qiniu', function ($app, $config) { 15 | $adapter = new QiniuAdapter( 16 | $config['access_key'], 17 | $config['secret_key'], 18 | $config['bucket'], 19 | $config['domain'] 20 | ); 21 | 22 | return new FilesystemAdapter(new Filesystem($adapter), $adapter, $config); 23 | }); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "overtrue/laravel-filesystem-qiniu", 3 | "description": "A Qiniu storage filesystem for Laravel.", 4 | "require": { 5 | "laravel/framework": "^9.0|^10.0|^11.0|^12.0", 6 | "overtrue/flysystem-qiniu": "^3.0" 7 | }, 8 | "require-dev": { 9 | "phpunit/phpunit": "^11.2", 10 | "mockery/mockery": "^1.4", 11 | "brainmaestro/composer-git-hooks": "dev-master", 12 | "laravel/pint": "^1.5" 13 | }, 14 | "autoload": { 15 | "psr-4": { 16 | "Overtrue\\LaravelFilesystem\\Qiniu\\": "src" 17 | } 18 | }, 19 | "authors": [ 20 | { 21 | "name": "overtrue", 22 | "email": "i@overtrue.me" 23 | } 24 | ], 25 | "license": "MIT", 26 | "extra": { 27 | "laravel": { 28 | "providers": [ 29 | "Overtrue\\LaravelFilesystem\\Qiniu\\QiniuStorageServiceProvider" 30 | ] 31 | }, 32 | "hooks": { 33 | "pre-commit": [ 34 | "composer check-style" 35 | ], 36 | "pre-push": [ 37 | "composer check-style" 38 | ] 39 | } 40 | }, 41 | "scripts": { 42 | "post-update-cmd": [ 43 | "cghooks update" 44 | ], 45 | "post-merge": "composer install", 46 | "post-install-cmd": [ 47 | "cghooks add --ignore-lock", 48 | "cghooks update" 49 | ], 50 | "cghooks": "vendor/bin/cghooks", 51 | "check-style": "vendor/bin/pint --test", 52 | "fix-style": "vendor/bin/pint", 53 | "test": "vendor/bin/phpunit" 54 | }, 55 | "scripts-descriptions": { 56 | "test": "Run all tests.", 57 | "check-style": "Run style checks (only dry run - no fixing!).", 58 | "fix-style": "Run style checks and fix violations." 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel filesystem Qiniu 2 | 3 | [Qiniu](http://www.qiniu.com/) storage for Laravel based on [overtrue/flysystem-qiniu](https://github.com/overtrue/flysystem-qiniu). 4 | 5 | [![Sponsor me](https://github.com/overtrue/overtrue/blob/master/sponsor-me-button-s.svg?raw=true)](https://github.com/sponsors/overtrue) 6 | 7 | # Requirement 8 | 9 | - Laravel >= 9.0 10 | 11 | # Installation 12 | 13 | ```shell 14 | $ composer require "overtrue/laravel-filesystem-qiniu" 15 | ``` 16 | 17 | # Configuration 18 | 19 | 1. After installing the library, register the `Overtrue\LaravelFilesystem\Qiniu\QiniuStorageServiceProvider` in your `config/app.php` file: 20 | 21 | ```php 22 | 'providers' => [ 23 | // Other service providers... 24 | Overtrue\LaravelFilesystem\Qiniu\QiniuStorageServiceProvider::class, 25 | ], 26 | ``` 27 | 28 | 2. Add a new disk to your `config/filesystems.php` config: 29 | 30 | ```php 31 | [ 35 | //... 36 | 'qiniu' => [ 37 | 'driver' => 'qiniu', 38 | 'access_key' => env('QINIU_ACCESS_KEY', 'xxxxxxxxxxxxxxxx'), 39 | 'secret_key' => env('QINIU_SECRET_KEY', 'xxxxxxxxxxxxxxxx'), 40 | 'bucket' => env('QINIU_BUCKET', 'test'), 41 | 'domain' => env('QINIU_DOMAIN', 'xxx.clouddn.com'), // or host: https://xxxx.clouddn.com 42 | ], 43 | //... 44 | ] 45 | ]; 46 | ``` 47 | 48 | # Usage 49 | 50 | ```php 51 | $disk = Storage::disk('qiniu'); 52 | 53 | // create a file 54 | $disk->put('avatars/filename.jpg', $fileContents); 55 | 56 | // check if a file exists 57 | $exists = $disk->has('file.jpg'); 58 | 59 | // get timestamp 60 | $time = $disk->lastModified('file1.jpg'); 61 | 62 | // copy a file 63 | $disk->copy('old/file1.jpg', 'new/file1.jpg'); 64 | 65 | // move a file 66 | $disk->move('old/file1.jpg', 'new/file1.jpg'); 67 | 68 | // get file contents 69 | $contents = $disk->read('folder/my_file.txt'); 70 | 71 | // fetch url content 72 | $file = $disk->getAdapter()->fetch('folder/save_as.txt', $fromUrl); 73 | 74 | // get file url 75 | $url = $disk->getAdapter()->getUrl('folder/my_file.txt'); 76 | 77 | // get file upload token 78 | $token = $disk->getAdapter()->getUploadToken('folder/my_file.txt'); 79 | $token = $disk->getAdapter()->getUploadToken('folder/my_file.txt', 3600); 80 | 81 | // get private url 82 | $url = $disk->getAdapter()->privateDownloadUrl('folder/my_file.txt'); 83 | ``` 84 | 85 | [Full API documentation.](http://flysystem.thephpleague.com/api/) 86 | 87 | ## :heart: Sponsor me 88 | 89 | [![Sponsor me](https://github.com/overtrue/overtrue/blob/master/sponsor-me.svg?raw=true)](https://github.com/sponsors/overtrue) 90 | 91 | 如果你喜欢我的项目并想支持它,[点击这里 :heart:](https://github.com/sponsors/overtrue) 92 | 93 | ## Project supported by JetBrains 94 | 95 | Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects. 96 | 97 | [![](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)](https://www.jetbrains.com/?from=https://github.com/overtrue) 98 | 99 | ## PHP 扩展包开发 100 | 101 | > 想知道如何从零开始构建 PHP 扩展包? 102 | > 103 | > 请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— [《PHP 扩展包实战教程 - 从入门到发布》](https://learnku.com/courses/creating-package) 104 | 105 | # License 106 | 107 | MIT 108 | --------------------------------------------------------------------------------