| Cloud | Multiple file uploads | Base64 picture upload | Server file upload |
|---|---|---|---|
| ? Private Cloud | ✅ | -- | ✅ |
| ? Alibaba Cloud | ✅ | ✅ | ✅ |
| ? Tencent Cloud | ✅ | ✅ | ✅ |
| ? Qiniu Cloud | ✅ | ✅ | ✅ |
| ? Amazon (S3) | ✅ | ✅ | ✅ |
composer require tinywan/storage $ res = Tinywan Storage Storage:: uploadFile ();
var_dump ( json_encode ( $ res ));
Afterv1.0.0, this method does not need to be called after the initializationTinywanStorageStorage::config(), it will be automatically initialized. The default configuration is the configuration fileapp.phpdefaultconfiguration configuration upload adapter.
[
{
"key" : " webman " ,
"origin_name" : "常用编程软件和工具.xlsx " ,
"save_name" : " 03414c9bdaf7a38148742c87b96b8167.xlsx " ,
"save_path" : " runtime/storage/03414c9bdaf7a38148742c87b96b8167.xlsx " ,
"save_path" : " /var/www/webman-admin/public/storage/03414c9bdaf7a38148742c87b96b8167.xlsx " ,
"url" : " /storage/fd2d472da56c71a6da0a5251f5e1b586.png " ,
"uniqid " : " 03414c9bdaf7a38148742c87b96b8167 " ,
"size" : 15050 ,
"mime_type" : " application/vnd.openxmlformats-officedocument.spreadsheetml.sheet " ,
"extension" : " xlsx "
}
...
]Failed, throwing
StorageAdapterExceptionexception
| Fields | describe | Example Values |
|---|---|---|
| key | Upload file key | webman |
| origin_name | Original file name | Common programming software and tools.xlsx |
| save_name | Save file name | 03414c9bdaf7a38148742c87b96b8167.xlsx |
| save_path | File saving path (relative) | /var/www/webman-admin/runtime/storage/03414c9bdaf7a38148742c87b96b8167.xlsx |
| url | URL access path | /storage/03414c9bdaf7a38148742c87b96b8167.xlsx |
| unique_id | Uniqid | 03414c9bdaf7a38148742c87b96b8167 |
| size | File size | 15050 (bytes) |
| mime_type | File Type | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet |
| extension | File extension | xlsx |
By default, it is uploaded to the local server. A file with the current date as a subdirectory and the file name encoded by the sha1 of the file stream will be generated under runtime/storage directory. For example, the file name generated above may be:
runtime/storage/fd2d472da56c71a6da0a5251f5e1b586.png
If you want the uploaded file to be directly accessible or downloaded, you can use public storage method.
You can configure the upload root directory in the config/plugin/tinywan/storage/app.php configuration file, for example:
' local ' => [
' adapter ' => Tinywan Storage Adapter LocalAdapter::class,
' root ' => public_path () . ' /storage ' ,
],Browser access: http://127.0.0.1:8787/storage/fd2d472da56c71a6da0a5251f5e1b586.png
Supports verification of uploaded files using verification classes, including file size, file type and suffix
| Fields | describe | Example Values |
|---|---|---|
| single_limit | The size limit for a single file, default 200M | 1024 * 1024 * 200 |
| Total_limit total_limit | All files size limit, default 200M | 1024 * 1024 * 200 |
| nums | File number limit, default 10 | 10 |
| include | List of allowed file types | ['xlsx','pdf'] |
| exclude | List of unauthorized file types | ['png','jpg'] |
composer require aliyuncs/oss-sdk-phpcomposer require qcloud/cos-sdk-v5composer require qiniu/php-sdkcomposer require league/flysystem-aws-s3-v3Use scenario: Direct screenshot of the front-end (ava, Canvas, etc.) A picture of the Base64 data stream is uploaded directly to the cloud
{
"extension" : " png " ,
"base64" : " data:image/jpeg;base64,/9j/4AAQSkxxxxxxxxxxxxZJRgABvtyQBIr/MPTPTP/2Q== "
} public function upload ( Request $ request )
{
$ base64 = $ request -> post ( ' base64 ' );
$ response = Tinywan Storage Storage:: disk ( Tinywan Storage Storage:: MODE_OSS , false )-> uploadBase64 ( $ base64 , ' png ' );
var_dump ( $ response );
}
Afterv1.0.0, this method does not need to be called after the initializationTinywanStorageStorage::config(), it will be automatically initialized. The default configuration is the configuration fileapp.phpdefaultconfiguration configuration upload adapter.
{
"save_path" : " storage/20220402213639624851671439e.png " ,
"url" : " http://webman.oss.tinywan.com/storage/20220402213639624851671439e.png " ,
"unique_id" : " 20220402213639624851671439e " ,
"size" : 11802 ,
"extension" : " png "
}Usage scenario: The server exports files need to be uploaded to cloud storage, or downloaded at zero time file storage.
$ serverFile = runtime_path () . DIRECTORY_SEPARATOR . ' storage/webman.png ' ;
$ res = Tinywan Storage Storage:: disk ( Tinywan Storage Storage:: MODE_OSS , false )-> uploadServerFile ( $ serverFile );
Afterv1.0.0, this method does not need to be called after the initializationTinywanStorageStorage::config(), it will be automatically initialized. The default configuration is the configuration fileapp.phpdefaultconfiguration configuration upload adapter.
{
"origin_name" : " /var/www/webman-admin/runtime/storage/webman.png " ,
"save_path" : " storage/6edf04d7c26f020cf5e46e6457620220402213414.png " ,
"url" : " http://webman.oss.tinywan.com/storage/6ed9ffd54d0df57620220402213414.png " ,
"unique_id" : " 6edf04d7c26f020cf5e46e6403213414 " ,
"size" : 3505604 ,
"extension" : " png "
} vendor/bin/phpstan analyse src
vendor/bin/php-cs-fixer fix src