在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1.首先注册七牛云存储账号 http://www.qiniu.com/ 2.获得密钥 3.仔细查看文档 http://developer.qiniu.com/docs/v6/sdk/php-sdk.html#io-put-flow 4.下载sdk 可以使用composer,也可以直接使用压缩包进行下载 5.在项目中引入七牛的类包 6.获得token 代码: <?php use Qiniu\Auth; $accessKey = 'ntL5AciwhaAa35APXKCSlC4KoUKyN77KNPmbHW0K'; $bucket = 'bucket'; 结果: string 'ntL5AciwhaAa35APXKCSlC4KoUKyN77KNPmbHW0K:H_W87vY-abWaHvOKpzVNGdwNUbc=:eyJzY29wZSI6ImJ1Y2tldCIsImRlYWRsaW5lIjoxNDM3OTc3ODAyfQ==' (length=126)
7.上传字符串 代码: <?php use Qiniu\Auth; $accessKey = '你的accessKey'; $bucket = 'bucket'; // 设置put policy的其他参数, 上传回调 $token = $auth->uploadToken($bucket); list($ret, $err) = $uploadMgr->put($token, null, 'content string'); 结果: ====> put result: array (size=2)
'hash' =>
string 'FkRvouCaQN6HmCyPmMuBd0OnhiOi' (length=28) 'key' => string 'FkRvouCaQN6HmCyPmMuBd0OnhiOi' (length=28) <?php use Qiniu\Auth; $accessKey = '你的accessKey'; $bucket = 'bucket'; // 设置put policy的其他参数, 上传回调 $token = $auth->uploadToken($bucket); list($ret, $err) = $uploadMgr->putFile($token, null, "desert.jpg"); 结果:
array (size=2)
'hash' =>
string
'FjBCDRqa-yvLYDNYElaa9ENaWc4X' (length=28) 'key' => string
'FjBCDRqa-yvLYDNYElaa9ENaWc4X' (length=28)
9.下载图片(私有,如果公有的话,不用key值) <?php use Qiniu\Auth; $accessKey = '你的accessKey'; $baseUrl = 'http://7xkofd.com1.z0.glb.clouddn.com/FtmX4cN-3AWth9A2A-Mq1JXuLPzh'; $downloaded_file = fopen($save_to, 'w'); }
|
2022-08-17
2022-07-18
2022-11-06
2022-08-17
2022-07-30
请发表评论