1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- /*
- |--------------------------------------------------------------------------
- | 查看图片的几个方法
- |--------------------------------------------------------------------------
- */
- namespace Upload\Src;
- use Dever;
- Dever::apply('sdk/qiniu', 'upload');
- class Qiniu
- {
- public function callback()
- {
- $body = file_get_contents('php://input');
- file_put_contents(Dever::data() . "test.txt",$body);
- $body = json_decode($body, true);
- $fname = $body['filename'];
- $fkey = $body['fkey'];
- $filesize = $body['filesize'];
- $width = $body['width'];
- $height = $body['height'];
- $arr=array("date"=>"test");
- echo json_encode($arr);
- }
- public function token()
- {
- $key = Dever::input('key');
- $upload = Dever::db('upload/upload')->one($key);
- if (!$upload) {
- return;
- }
-
- $config = Dever::db('upload/yun')->one($upload['yun']);
- $accessKey = $config['appkey'];
- $secretKey = $config['appsecret'];
- $host = $config['host'];
- $auth = new \Qiniu\Auth($accessKey, $secretKey);
- $bucket = $upload['bucket'];
- $policy = array(
- 'callbackUrl' => Dever::url('qiniu.callback', 'upload'),
- 'callbackBody' => 'filename=$(fname)&fkey=$(key)&filesize=$(fsize)&width=$(imageInfo.width)&height=$(imageInfo.height)'
- );
- // 生成上传Token
- $token = $auth->uploadToken($bucket, null, 3600);
- $domain = 'http://up-z1.qiniup.com/';
- $ret = array('uptoken' => $token, 'domain' => $domain, 'host' => $config['host']);
- echo json_encode($ret);die;
- }
- }
|