Showing
15 changed files
with
467 additions
and
0 deletions
vendor/Qiniu/examples/rs_delete.php
0 → 100755
| 1 | +<?php | ||
| 2 | +require_once __DIR__ . '/../autoload.php'; | ||
| 3 | + | ||
| 4 | +use \Qiniu\Auth; | ||
| 5 | + | ||
| 6 | +$accessKey = getenv('QINIU_ACCESS_KEY'); | ||
| 7 | +$secretKey = getenv('QINIU_SECRET_KEY'); | ||
| 8 | +$bucket = getenv('QINIU_TEST_BUCKET'); | ||
| 9 | + | ||
| 10 | +$key = "qiniu.mp4_copy"; | ||
| 11 | +$auth = new Auth($accessKey, $secretKey); | ||
| 12 | +$config = new \Qiniu\Config(); | ||
| 13 | +$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config); | ||
| 14 | +$err = $bucketManager->delete($bucket, $key); | ||
| 15 | +if ($err) { | ||
| 16 | + print_r($err); | ||
| 17 | +} |
| 1 | +<?php | ||
| 2 | +require_once __DIR__ . '/../autoload.php'; | ||
| 3 | + | ||
| 4 | +use \Qiniu\Auth; | ||
| 5 | + | ||
| 6 | +$accessKey = getenv('QINIU_ACCESS_KEY'); | ||
| 7 | +$secretKey = getenv('QINIU_SECRET_KEY'); | ||
| 8 | +$bucket = getenv('QINIU_TEST_BUCKET'); | ||
| 9 | + | ||
| 10 | +$key = 'qiniu.mp4'; | ||
| 11 | +$days = 10; | ||
| 12 | + | ||
| 13 | +$auth = new Auth($accessKey, $secretKey); | ||
| 14 | +$config = new \Qiniu\Config(); | ||
| 15 | +$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config); | ||
| 16 | + | ||
| 17 | +$err = $bucketManager->deleteAfterDays($bucket, $key, $days); | ||
| 18 | +if ($err) { | ||
| 19 | + print_r($err); | ||
| 20 | +} |
vendor/Qiniu/examples/rs_download_urls.php
0 → 100755
| 1 | +<?php | ||
| 2 | +require_once __DIR__ . '/../autoload.php'; | ||
| 3 | + | ||
| 4 | +use Qiniu\Auth; | ||
| 5 | + | ||
| 6 | +$accessKey = getenv('QINIU_ACCESS_KEY'); | ||
| 7 | +$secretKey = getenv('QINIU_SECRET_KEY'); | ||
| 8 | + | ||
| 9 | +// 构建Auth对象 | ||
| 10 | +$auth = new Auth($accessKey, $secretKey); | ||
| 11 | + | ||
| 12 | +// 私有空间中的外链 http://<domain>/<file_key> | ||
| 13 | +$baseUrl = 'http://if-pri.qiniudn.com/qiniu.png?imageView2/1/h/500'; | ||
| 14 | +// 对链接进行签名 | ||
| 15 | +$signedUrl = $auth->privateDownloadUrl($baseUrl); | ||
| 16 | + | ||
| 17 | +echo $signedUrl; |
vendor/Qiniu/examples/rs_fetch.php
0 → 100755
| 1 | +<?php | ||
| 2 | +require_once __DIR__ . '/../autoload.php'; | ||
| 3 | + | ||
| 4 | +use Qiniu\Auth; | ||
| 5 | +use Qiniu\Storage\BucketManager; | ||
| 6 | + | ||
| 7 | +$accessKey = getenv('QINIU_ACCESS_KEY'); | ||
| 8 | +$secretKey = getenv('QINIU_SECRET_KEY'); | ||
| 9 | +$bucket = getenv('QINIU_TEST_BUCKET'); | ||
| 10 | + | ||
| 11 | +$auth = new Auth($accessKey, $secretKey); | ||
| 12 | +$bucketManager = new BucketManager($auth); | ||
| 13 | + | ||
| 14 | +$url = 'http://devtools.qiniu.com/qiniu.png'; | ||
| 15 | +$key = time() . '.png'; | ||
| 16 | + | ||
| 17 | +// 指定抓取的文件保存名称 | ||
| 18 | +list($ret, $err) = $bucketManager->fetch($url, $bucket, $key); | ||
| 19 | +echo "=====> fetch $url to bucket: $bucket key: $key\n"; | ||
| 20 | +if ($err !== null) { | ||
| 21 | + var_dump($err); | ||
| 22 | +} else { | ||
| 23 | + print_r($ret); | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +// 不指定key时,以文件内容的hash作为文件名 | ||
| 27 | +$key = null; | ||
| 28 | +list($ret, $err) = $bucketManager->fetch($url, $bucket, $key); | ||
| 29 | +echo "=====> fetch $url to bucket: $bucket key: $(etag)\n"; | ||
| 30 | +if ($err !== null) { | ||
| 31 | + var_dump($err); | ||
| 32 | +} else { | ||
| 33 | + print_r($ret); | ||
| 34 | +} |
vendor/Qiniu/examples/rs_move.php
0 → 100755
| 1 | +<?php | ||
| 2 | +require_once __DIR__ . '/../autoload.php'; | ||
| 3 | + | ||
| 4 | +use \Qiniu\Auth; | ||
| 5 | + | ||
| 6 | +$accessKey = getenv('QINIU_ACCESS_KEY'); | ||
| 7 | +$secretKey = getenv('QINIU_SECRET_KEY'); | ||
| 8 | +$bucket = getenv('QINIU_TEST_BUCKET'); | ||
| 9 | + | ||
| 10 | +$key = "qiniu.mp4"; | ||
| 11 | +$auth = new Auth($accessKey, $secretKey); | ||
| 12 | +$config = new \Qiniu\Config(); | ||
| 13 | +$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config); | ||
| 14 | + | ||
| 15 | +$srcBucket = $bucket; | ||
| 16 | +$destBucket = $bucket; | ||
| 17 | +$srcKey = $key . "_copy"; | ||
| 18 | +$destKey = $key . "_move"; | ||
| 19 | +$err = $bucketManager->move($srcBucket, $srcKey, $destBucket, $destKey, true); | ||
| 20 | +if ($err) { | ||
| 21 | + print_r($err); | ||
| 22 | +} |
vendor/Qiniu/examples/rs_prefetch.php
0 → 100755
| 1 | +<?php | ||
| 2 | +require_once __DIR__ . '/../autoload.php'; | ||
| 3 | + | ||
| 4 | +use \Qiniu\Auth; | ||
| 5 | + | ||
| 6 | +$accessKey = getenv('QINIU_ACCESS_KEY'); | ||
| 7 | +$secretKey = getenv('QINIU_SECRET_KEY'); | ||
| 8 | +$bucket = getenv('QINIU_TEST_BUCKET'); | ||
| 9 | + | ||
| 10 | +$key = "qiniu.mp4"; | ||
| 11 | +$auth = new Auth($accessKey, $secretKey); | ||
| 12 | +$config = new \Qiniu\Config(); | ||
| 13 | +$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config); | ||
| 14 | +$err = $bucketManager->prefetch($bucket, $key); | ||
| 15 | +if ($err) { | ||
| 16 | + print_r($err); | ||
| 17 | +} |
vendor/Qiniu/examples/rs_stat.php
0 → 100755
| 1 | +<?php | ||
| 2 | +require_once __DIR__ . '/../autoload.php'; | ||
| 3 | + | ||
| 4 | +use \Qiniu\Auth; | ||
| 5 | + | ||
| 6 | +$accessKey = getenv('QINIU_ACCESS_KEY'); | ||
| 7 | +$secretKey = getenv('QINIU_SECRET_KEY'); | ||
| 8 | +$bucket = getenv('QINIU_TEST_BUCKET'); | ||
| 9 | + | ||
| 10 | +$key = "qiniu.mp4"; | ||
| 11 | +$auth = new Auth($accessKey, $secretKey); | ||
| 12 | +$config = new \Qiniu\Config(); | ||
| 13 | +$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config); | ||
| 14 | +list($fileInfo, $err) = $bucketManager->stat($bucket, $key); | ||
| 15 | +if ($err) { | ||
| 16 | + print_r($err); | ||
| 17 | +} else { | ||
| 18 | + print_r($fileInfo); | ||
| 19 | +} |
vendor/Qiniu/examples/rsf_list_bucket.php
0 → 100755
| 1 | +<?php | ||
| 2 | +require_once __DIR__ . '/../autoload.php'; | ||
| 3 | + | ||
| 4 | +use Qiniu\Auth; | ||
| 5 | +use Qiniu\Storage\BucketManager; | ||
| 6 | + | ||
| 7 | +// http://developer.qiniu.com/docs/v6/api/reference/rs/list.html#list-description | ||
| 8 | + | ||
| 9 | +$accessKey = getenv('QINIU_ACCESS_KEY'); | ||
| 10 | +$secretKey = getenv('QINIU_SECRET_KEY'); | ||
| 11 | +$bucket = getenv('QINIU_TEST_BUCKET'); | ||
| 12 | +$auth = new Auth($accessKey, $secretKey); | ||
| 13 | +$bucketManager = new BucketManager($auth); | ||
| 14 | + | ||
| 15 | + | ||
| 16 | +// 要列取文件的公共前缀 | ||
| 17 | +$prefix = ''; | ||
| 18 | + | ||
| 19 | +// 上次列举返回的位置标记,作为本次列举的起点信息。 | ||
| 20 | +$marker = ''; | ||
| 21 | + | ||
| 22 | +// 本次列举的条目数 | ||
| 23 | +$limit = 200; | ||
| 24 | + | ||
| 25 | +$delimiter = '/'; | ||
| 26 | + | ||
| 27 | +// 列举文件 | ||
| 28 | +do { | ||
| 29 | + list($ret, $err) = $bucketManager->listFiles($bucket, $prefix, $marker, $limit, $delimiter); | ||
| 30 | + if ($err !== null) { | ||
| 31 | + echo "\n====> list file err: \n"; | ||
| 32 | + var_dump($err); | ||
| 33 | + } else { | ||
| 34 | + $marker = null; | ||
| 35 | + if (array_key_exists('marker', $ret)) { | ||
| 36 | + $marker = $ret['marker']; | ||
| 37 | + } | ||
| 38 | + echo "Marker: $marker\n"; | ||
| 39 | + echo "\nList Items====>\n"; | ||
| 40 | + //var_dump($ret['items']); | ||
| 41 | + print('items count:' . count($ret['items']) . "\n"); | ||
| 42 | + if (array_key_exists('commonPrefixes', $ret)) { | ||
| 43 | + print_r($ret['commonPrefixes']); | ||
| 44 | + } | ||
| 45 | + } | ||
| 46 | +} while (!empty($marker)); |
vendor/Qiniu/examples/rsf_list_files.php
0 → 100755
| 1 | +<?php | ||
| 2 | +require_once __DIR__ . '/../autoload.php'; | ||
| 3 | + | ||
| 4 | +use Qiniu\Auth; | ||
| 5 | +use Qiniu\Storage\BucketManager; | ||
| 6 | + | ||
| 7 | +// http://developer.qiniu.com/docs/v6/api/reference/rs/list.html#list-description | ||
| 8 | + | ||
| 9 | +$accessKey = getenv('QINIU_ACCESS_KEY'); | ||
| 10 | +$secretKey = getenv('QINIU_SECRET_KEY'); | ||
| 11 | +$bucket = getenv('QINIU_TEST_BUCKET'); | ||
| 12 | +$auth = new Auth($accessKey, $secretKey); | ||
| 13 | +$bucketManager = new BucketManager($auth); | ||
| 14 | + | ||
| 15 | + | ||
| 16 | +// 要列取文件的公共前缀 | ||
| 17 | +$prefix = ''; | ||
| 18 | + | ||
| 19 | +// 上次列举返回的位置标记,作为本次列举的起点信息。 | ||
| 20 | +$marker = ''; | ||
| 21 | + | ||
| 22 | +// 本次列举的条目数 | ||
| 23 | +$limit = 100; | ||
| 24 | + | ||
| 25 | +$delimiter = '/'; | ||
| 26 | + | ||
| 27 | +// 列举文件 | ||
| 28 | +list($ret, $err) = $bucketManager->listFiles($bucket, $prefix, $marker, $limit, $delimiter); | ||
| 29 | +if ($err !== null) { | ||
| 30 | + echo "\n====> list file err: \n"; | ||
| 31 | + var_dump($err); | ||
| 32 | +} else { | ||
| 33 | + if (array_key_exists('marker', $ret)) { | ||
| 34 | + echo "Marker:" . $ret["marker"] . "\n"; | ||
| 35 | + } | ||
| 36 | + echo "\nList Iterms====>\n"; | ||
| 37 | + //var_dump($ret['items']); | ||
| 38 | +} |
vendor/Qiniu/examples/saveas.php
0 → 100755
| 1 | +<?php | ||
| 2 | +require_once __DIR__ . '/../autoload.php'; | ||
| 3 | + | ||
| 4 | +use Qiniu\Auth; | ||
| 5 | +use Qiniu\Processing\PersistentFop; | ||
| 6 | + | ||
| 7 | +// 后台来获取AK, SK | ||
| 8 | +$accessKey = 'Access_Key'; | ||
| 9 | +$secretKey = 'Secret_Key'; | ||
| 10 | + | ||
| 11 | +//生成EncodedEntryURI的值 | ||
| 12 | +$entry = '<bucket>:<Key>';//<Key>为生成缩略图的文件名 | ||
| 13 | +//生成的值 | ||
| 14 | +$encodedEntryURI = \Qiniu\base64_urlSafeEncode($entry); | ||
| 15 | + | ||
| 16 | +//使用SecretKey对新的下载URL进行HMAC1-SHA1签名 | ||
| 17 | +$newurl = "78re52.com1.z0.glb.clouddn.com/resource/Ship.jpg?imageView2/2/w/200/h/200|saveas/" . $encodedEntryURI; | ||
| 18 | + | ||
| 19 | +$sign = hash_hmac("sha1", $newurl, $secretKey, true); | ||
| 20 | + | ||
| 21 | +//对签名进行URL安全的Base64编码 | ||
| 22 | +$encodedSign = \Qiniu\base64_urlSafeEncode($sign); | ||
| 23 | +//最终得到的完整下载URL | ||
| 24 | +$finalURL = "http://" . $newurl . "/sign/" . $accessKey . ":" . $encodedSign; | ||
| 25 | + | ||
| 26 | +$callbackBody = file_get_contents("$finalURL"); | ||
| 27 | + | ||
| 28 | +echo $callbackBody; |
| 1 | +<?php | ||
| 2 | +require_once __DIR__ . '/../autoload.php'; | ||
| 3 | + | ||
| 4 | +use Qiniu\Auth; | ||
| 5 | +use Qiniu\Storage\UploadManager; | ||
| 6 | + | ||
| 7 | +$accessKey = getenv('QINIU_ACCESS_KEY'); | ||
| 8 | +$secretKey = getenv('QINIU_SECRET_KEY'); | ||
| 9 | +$bucket = getenv('QINIU_TEST_BUCKET'); | ||
| 10 | +$auth = new Auth($accessKey, $secretKey); | ||
| 11 | + | ||
| 12 | +// 上传文件到七牛后, 七牛将文件名和文件大小回调给业务服务器. | ||
| 13 | +// 可参考文档: http://developer.qiniu.com/docs/v6/api/reference/security/put-policy.html | ||
| 14 | +$policy = array( | ||
| 15 | + 'callbackUrl' => 'http://your.domain.com/upload_verify_callback.php', | ||
| 16 | + 'callbackBody' => 'filename=$(fname)&filesize=$(fsize)' | ||
| 17 | +); | ||
| 18 | +$uptoken = $auth->uploadToken($bucket, null, 3600, $policy); | ||
| 19 | + | ||
| 20 | +//上传文件的本地路径 | ||
| 21 | +$filePath = './php-logo.png'; | ||
| 22 | + | ||
| 23 | +$uploadMgr = new UploadManager(); | ||
| 24 | + | ||
| 25 | +list($ret, $err) = $uploadMgr->putFile($uptoken, null, $filePath); | ||
| 26 | +echo "\n====> putFile result: \n"; | ||
| 27 | +if ($err !== null) { | ||
| 28 | + var_dump($err); | ||
| 29 | +} else { | ||
| 30 | + var_dump($ret); | ||
| 31 | +} |
vendor/Qiniu/examples/upload_and_pfop.php
0 → 100755
| 1 | +<?php | ||
| 2 | +require_once __DIR__ . '/../autoload.php'; | ||
| 3 | + | ||
| 4 | +use Qiniu\Auth; | ||
| 5 | +use Qiniu\Storage\UploadManager; | ||
| 6 | + | ||
| 7 | +$accessKey = getenv('QINIU_ACCESS_KEY'); | ||
| 8 | +$secretKey = getenv('QINIU_SECRET_KEY'); | ||
| 9 | +$bucket = getenv('QINIU_TEST_BUCKET'); | ||
| 10 | +$auth = new Auth($accessKey, $secretKey); | ||
| 11 | + | ||
| 12 | + | ||
| 13 | +// 在七牛保存的文件名 | ||
| 14 | +$key = 'php-logo.png'; | ||
| 15 | +$uploadMgr = new UploadManager(); | ||
| 16 | + | ||
| 17 | +$pfop = "imageMogr2/rotate/90|saveas/" . \Qiniu\base64_urlSafeEncode($bucket . ":php-logo-rotate.png"); | ||
| 18 | + | ||
| 19 | +//转码完成后通知到你的业务服务器。(公网可以访问,并相应200 OK) | ||
| 20 | +$notifyUrl = 'http://notify.fake.com'; | ||
| 21 | + | ||
| 22 | +//独立的转码队列:https://portal.qiniu.com/mps/pipeline | ||
| 23 | +$pipeline = 'sdktest'; | ||
| 24 | + | ||
| 25 | +$policy = array( | ||
| 26 | + 'persistentOps' => $pfop, | ||
| 27 | + 'persistentNotifyUrl' => $notifyUrl, | ||
| 28 | + 'persistentPipeline' => $pipeline | ||
| 29 | +); | ||
| 30 | +$token = $auth->uploadToken($bucket, null, 3600, $policy); | ||
| 31 | + | ||
| 32 | +list($ret, $err) = $uploadMgr->putFile($token, null, $key); | ||
| 33 | +echo "\n====> putFile result: \n"; | ||
| 34 | +if ($err !== null) { | ||
| 35 | + var_dump($err); | ||
| 36 | +} else { | ||
| 37 | + var_dump($ret); | ||
| 38 | +} |
vendor/Qiniu/examples/upload_mgr_init.php
0 → 100755
| 1 | +<?php | ||
| 2 | +require_once __DIR__ . '/../autoload.php'; | ||
| 3 | + | ||
| 4 | +use Qiniu\Auth; | ||
| 5 | +use Qiniu\Storage\UploadManager; | ||
| 6 | + | ||
| 7 | +$accessKey = 'Access_Key'; | ||
| 8 | +$secretKey = 'Secret_Key'; | ||
| 9 | +$auth = new Auth($accessKey, $secretKey); | ||
| 10 | + | ||
| 11 | +// 空间名 http://developer.qiniu.com/docs/v6/api/overview/concepts.html#bucket | ||
| 12 | +$bucket = 'Bucket_Name'; | ||
| 13 | + | ||
| 14 | +// 生成上传Token | ||
| 15 | +$token = $auth->uploadToken($bucket); | ||
| 16 | + | ||
| 17 | +// 构建 UploadManager 对象 | ||
| 18 | +$uploadMgr = new UploadManager(); |
vendor/Qiniu/examples/upload_multi_demos.php
0 → 100755
| 1 | +<?php | ||
| 2 | +require_once __DIR__ . '/../autoload.php'; | ||
| 3 | + | ||
| 4 | +use Qiniu\Auth; | ||
| 5 | +use Qiniu\Storage\UploadManager; | ||
| 6 | + | ||
| 7 | +$accessKey = getenv('QINIU_ACCESS_KEY'); | ||
| 8 | +$secretKey = getenv('QINIU_SECRET_KEY'); | ||
| 9 | +$bucket = getenv('QINIU_TEST_BUCKET'); | ||
| 10 | +$pipeline = 'sdktest'; | ||
| 11 | + | ||
| 12 | +$auth = new Auth($accessKey, $secretKey); | ||
| 13 | +$token = $auth->uploadToken($bucket); | ||
| 14 | +$uploadMgr = new UploadManager(); | ||
| 15 | + | ||
| 16 | +//----------------------------------------upload demo1 ---------------------------------------- | ||
| 17 | +// 上传字符串到七牛 | ||
| 18 | +list($ret, $err) = $uploadMgr->put($token, null, 'content string'); | ||
| 19 | +echo "\n====> put result: \n"; | ||
| 20 | +if ($err !== null) { | ||
| 21 | + var_dump($err); | ||
| 22 | +} else { | ||
| 23 | + var_dump($ret); | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | + | ||
| 27 | +//----------------------------------------upload demo2 ---------------------------------------- | ||
| 28 | +// 上传文件到七牛 | ||
| 29 | +$filePath = './php-logo.png'; | ||
| 30 | +$key = 'php-logo.png'; | ||
| 31 | +list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath); | ||
| 32 | +echo "\n====> putFile result: \n"; | ||
| 33 | +if ($err !== null) { | ||
| 34 | + var_dump($err); | ||
| 35 | +} else { | ||
| 36 | + var_dump($ret); | ||
| 37 | +} | ||
| 38 | + | ||
| 39 | + | ||
| 40 | +//----------------------------------------upload demo3 ---------------------------------------- | ||
| 41 | +// 上传文件到七牛后, 七牛将文件名和文件大小回调给业务服务器. | ||
| 42 | +// 可参考文档: http://developer.qiniu.com/docs/v6/api/reference/security/put-policy.html | ||
| 43 | +$policy = array( | ||
| 44 | + 'callbackUrl' => 'http://172.30.251.210/upload_verify_callback.php', | ||
| 45 | + 'callbackBody' => 'filename=$(fname)&filesize=$(fsize)' | ||
| 46 | +// 'callbackBodyType' => 'application/json', | ||
| 47 | +// 'callbackBody' => '{"filename":$(fname), "filesize": $(fsize)}' //设置application/json格式回调 | ||
| 48 | +); | ||
| 49 | +$token = $auth->uploadToken($bucket, null, 3600, $policy); | ||
| 50 | + | ||
| 51 | + | ||
| 52 | +list($ret, $err) = $uploadMgr->putFile($token, null, $key); | ||
| 53 | +echo "\n====> putFile result: \n"; | ||
| 54 | +if ($err !== null) { | ||
| 55 | + var_dump($err); | ||
| 56 | +} else { | ||
| 57 | + var_dump($ret); | ||
| 58 | +} | ||
| 59 | + | ||
| 60 | + | ||
| 61 | +//----------------------------------------upload demo4 ---------------------------------------- | ||
| 62 | +//上传视频,上传完成后进行m3u8的转码, 并给视频打水印 | ||
| 63 | +$wmImg = Qiniu\base64_urlSafeEncode('http://devtools.qiniudn.com/qiniu.png'); | ||
| 64 | +$pfop = "avthumb/m3u8/wmImage/$wmImg"; | ||
| 65 | + | ||
| 66 | +//转码完成后回调到业务服务器。(公网可以访问,并相应200 OK) | ||
| 67 | +$notifyUrl = 'http://notify.fake.com'; | ||
| 68 | + | ||
| 69 | +//独立的转码队列:https://portal.qiniu.com/mps/pipeline | ||
| 70 | + | ||
| 71 | + | ||
| 72 | +$policy = array( | ||
| 73 | + 'persistentOps' => $pfop, | ||
| 74 | + 'persistentNotifyUrl' => $notifyUrl, | ||
| 75 | + 'persistentPipeline' => $pipeline | ||
| 76 | +); | ||
| 77 | +$token = $auth->uploadToken($bucket, null, 3600, $policy); | ||
| 78 | +print($token); | ||
| 79 | +list($ret, $err) = $uploadMgr->putFile($token, null, $key); | ||
| 80 | +echo "\n====> putFile result: \n"; | ||
| 81 | +if ($err !== null) { | ||
| 82 | + var_dump($err); | ||
| 83 | +} else { | ||
| 84 | + var_dump($ret); | ||
| 85 | +} |
vendor/Qiniu/examples/upload_simple_file.php
0 → 100755
| 1 | +<?php | ||
| 2 | +require_once __DIR__ . '/../autoload.php'; | ||
| 3 | + | ||
| 4 | +// 引入鉴权类 | ||
| 5 | +use Qiniu\Auth; | ||
| 6 | + | ||
| 7 | +// 引入上传类 | ||
| 8 | +use Qiniu\Storage\UploadManager; | ||
| 9 | + | ||
| 10 | +// 需要填写你的 Access Key 和 Secret Key | ||
| 11 | +$accessKey = getenv('QINIU_ACCESS_KEY'); | ||
| 12 | +$secretKey = getenv('QINIU_SECRET_KEY'); | ||
| 13 | +$bucket = getenv('QINIU_TEST_BUCKET'); | ||
| 14 | + | ||
| 15 | +// 构建鉴权对象 | ||
| 16 | +$auth = new Auth($accessKey, $secretKey); | ||
| 17 | + | ||
| 18 | +// 生成上传 Token | ||
| 19 | +$token = $auth->uploadToken($bucket); | ||
| 20 | + | ||
| 21 | +// 要上传文件的本地路径 | ||
| 22 | +$filePath = './php-logo.png'; | ||
| 23 | + | ||
| 24 | +// 上传到七牛后保存的文件名 | ||
| 25 | +$key = 'my-php-logo.png'; | ||
| 26 | + | ||
| 27 | +// 初始化 UploadManager 对象并进行文件的上传。 | ||
| 28 | +$uploadMgr = new UploadManager(); | ||
| 29 | + | ||
| 30 | +// 调用 UploadManager 的 putFile 方法进行文件的上传。 | ||
| 31 | +list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath); | ||
| 32 | +echo "\n====> putFile result: \n"; | ||
| 33 | +if ($err !== null) { | ||
| 34 | + var_dump($err); | ||
| 35 | +} else { | ||
| 36 | + var_dump($ret); | ||
| 37 | +} |
-
Please register or login to post a comment