|
@@ -16,15 +16,69 @@ class Qiniu
|
|
|
$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'];
|
|
|
+ $file = $body['filename'];
|
|
|
+ $key = $body['key'];
|
|
|
+ $size = $body['filesize'];
|
|
|
$width = $body['width'];
|
|
|
$height = $body['height'];
|
|
|
- $arr=array("date"=>"test");
|
|
|
- echo json_encode($arr);
|
|
|
+
|
|
|
+ $config = Dever::db('upload/upload')->one($key);
|
|
|
+
|
|
|
+ if ($config) {
|
|
|
+ $this->initFile($key, $file, $file, $width, $height, $size);
|
|
|
+ }
|
|
|
+ return 'ok';
|
|
|
}
|
|
|
|
|
|
+ private function initFile($key, $file, $source, $width = false, $height = false, $size = false)
|
|
|
+ {
|
|
|
+ $temp = explode('/', $file);
|
|
|
+ $name = $temp[count($temp) - 1];
|
|
|
+ $temp = explode('.', $name);
|
|
|
+ $name = $temp[0];
|
|
|
+ $ext = $temp[count($temp) - 1];
|
|
|
+
|
|
|
+ $info = Dever::load('upload/file-name', array('where_name' => $name, 'where_upload' => $key));
|
|
|
+
|
|
|
+ $data['name'] = $name;
|
|
|
+ $data['file'] = $file;
|
|
|
+ $data['key'] = md5($file);
|
|
|
+ $data['ext'] = $ext;
|
|
|
+
|
|
|
+ if ($width) {
|
|
|
+ $data['width'] = $width;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($height) {
|
|
|
+ $data['height'] = $height;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($size) {
|
|
|
+ $data['size'] = $size;
|
|
|
+ }
|
|
|
+ $data['upload'] = $key;
|
|
|
+ if ($info) {
|
|
|
+ $data['where_id'] = $info['id'];
|
|
|
+ Dever::db('upload/file')->update($data);
|
|
|
+ } else {
|
|
|
+ $data['source_name'] = $source;
|
|
|
+ Dever::db('upload/file')->insert($data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function addFile()
|
|
|
+ {
|
|
|
+ $file = Dever::input('file');
|
|
|
+ $key = Dever::input('key');
|
|
|
+ $source = Dever::input('source');
|
|
|
+
|
|
|
+ $config = Dever::db('upload/upload')->one($key);
|
|
|
+
|
|
|
+ if ($config) {
|
|
|
+ $this->initFile($key, $file, $source);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public function token()
|
|
|
{
|
|
|
$key = Dever::input('key');
|
|
@@ -42,7 +96,7 @@ class Qiniu
|
|
|
|
|
|
$policy = array(
|
|
|
'callbackUrl' => Dever::url('qiniu.callback', 'upload'),
|
|
|
- 'callbackBody' => 'filename=$(fname)&fkey=$(key)&filesize=$(fsize)&width=$(imageInfo.width)&height=$(imageInfo.height)'
|
|
|
+ 'callbackBody' => 'filename=$(fname)&key=$(key)&filesize=$(fsize)&width=$(imageInfo.width)&height=$(imageInfo.height)'
|
|
|
);
|
|
|
|
|
|
// 生成上传Token
|