PHP code example of tinymeng / uploads
1. Go to this page and download the library: Download tinymeng/uploads library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tinymeng / uploads example snippets
.
├── src 代码源文件目录
│ ├── Connector
│ │ ├── Gateway.php 必须继承的抽象类
│ │ └── GatewayInterface.php 必须实现的接口
│ ├── exception
│ │ └── TinymengException.php
│ ├── Gateways
│ │ ├── Cos.php
│ │ └── Oss.php
│ │ └── Qiniu.php
│ ├── Helper
│ │ ├── FileFunction.php
│ │ ├── MimeType.php
│ │ ├── PathLibrary.php
│ │ └── Str.php 字符串辅助类
│ └── Upload.php 抽象实例类
├── composer.json composer文件
├── LICENSE MIT License
└── README.md 说明文件
$config = [
'accessKeyId' => '',
'accessKeySecret' => '',
'endpoint' => '',
'isCName' => false,
'securityToken' => null,
'bucket' => '',
'timeout' => '5184000',
'connectTimeout' => '10',
'transport' => 'http',//如果支持https,请填写https,如果不支持请填写http
'max_keys' => 1000,//max-keys用于限定此次返回object的最大数,如果不设定,默认为100,max-keys取值不能大于1000
];
$drive = Upload::oss($config);
$a = $drive->uploadFile("test6.png", $_FILES['file']['tmp_name'] );//file上传文件
$image = "11/22/33/7125_yangxiansen.jpg";
$image2 = "111.png";
$image3 = "2.txt";
$drive = Upload::oss($config);
$drive->write("test2.txt", "111222",$config);
$drive->getMetadata($image2); //判断文件是否存在
$drive->geturl($image2); //获得文件的 url
$drive->has($image2); //判断文件是否存在
$drive->listContents(''); //列出文件列表
$drive->getSize($image2); //获得图片大小
$drive->getMimetype($image2); //获得图片mime类型
$drive->getTimestamp($image2); //获得图片上传时间戳
$drive->read($image3); //获得文件信息
$drive->readStream($image3); //获得文件信息
$drive->rename($image3, '4.txt/'); //重命名文件
$drive->copy('4.txt/', '/txt/5.txt'); //复制文件
$drive->delete('/txt/5.txt'); //删除文件
$drive->write("/txt/4.txt", $drive->read("/4.txt"); //上传文件
$drive->write("/test2.txt", "111222"); //上传文件
$drive->deleteDir('txt/'); //删除文件夹
$drive->createDir('test3/'); //创建文件夹
$handle = fopen('/tmp/email.png', 'r');
$drive->writeStream("/write/test3.png", $handle); //上传文件(文件流方式)
$drive->writeStream("/test6.png", $drive->readStream('/write/test3.png') ); //上传文件(文件流方式)
'qiniu' => [
'driver' => 'qiniu',
'domain' => '',//你的七牛域名
'access_key' => '',//AccessKey
'secret_key' => '',//SecretKey
'bucket' => '',//Bucket名字
'transport' => 'http',//如果支持https,请填写https,如果不支持请填写http
],
'oss' => [
'accessKeyId' => '',
'accessKeySecret' => '',
'endpoint' => '',
'isCName' => false,
'securityToken' => null,
'bucket' => '',
'timeout' => '5184000',
'connectTimeout' => '10',
'transport' => 'http',//如果支持https,请填写https,如果不支持请填写http
'max_keys' => 1000,//max-keys用于限定此次返回object的最大数,如果不设定,默认为100,max-keys取值不能大于1000
],
public Qcloud\Cos\Client upload(string $bucket, string $key, $body, array $options = array());
'cos' => [
'secretId' => '',
'secretKey' => '',
'bucket' => '',
'region' => 'ap-beijing',
'isCName' => false,
'securityToken' => null,
'timeout' => '5184000',
'connectTimeout' => '10',
'transport' => 'http',//如果支持https,请填写https,如果不支持请填写http
'max_keys' => 1000,//max-keys用于限定此次返回object的最大数,如果不设定,默认为100,max-keys取值不能大于1000
],