예제 #1
0
 public function upload()
 {
     $qiniu = \Qiniu\Qiniu::create(array('access_key' => config('quickcms.qiniu_access_key'), 'secret_key' => config('quickcms.qiniu_secret_key'), 'bucket' => config('quickcms.qiniu_bucket')));
     $file_name = Input::get('file_name');
     try {
         $image = Input::file($file_name);
         $upload_key = $file_name . '_' . date('YmdHis', time()) . rand(1, 9999);
         $photo = $qiniu->uploadFile($image->getRealPath(), $upload_key);
         $key = $photo->data['key'];
         $url = config('quickcms.qiniu_url') . '/' . $key;
         $thumbnailUrl = $url . '?imageView2/2/w/200/h/100';
         $success = new \stdClass();
         $success->name = $key;
         $success->size = json_decode(file_get_contents($url . '?stat'))->fsize;
         $success->url = $url;
         $success->thumbnailUrl = $thumbnailUrl;
         $success->photo_name = '';
         // TODO
         // Remove the file from qiniu when invoke the delete action
         $success->deleteUrl = route('admin.blueimp.delete', 1);
         // 处理删除的action
         $success->deleteType = 'GET';
         $success->key = $key;
         return Response::json(array('files' => array($success)), 200);
     } catch (Exception $e) {
         $error = new \stdClass();
         $error->error = $e->getMessage();
         $error->deleteUrl = route('admin.blueimp.delete', 'undefined');
         // 处理删除的action
         $error->deleteType = 'GET';
         return Response::json(array('files' => array($error)), 200);
     }
 }
예제 #2
0
 public function upload()
 {
     $qiniu = \Qiniu\Qiniu::create(array('access_key' => config('quickcms.qiniu_access_key'), 'secret_key' => config('quickcms.qiniu_secret_key'), 'bucket' => config('quickcms.qiniu_bucket')));
     try {
         $file = Input::file('file');
         $file_name = $file->getClientOriginalName();
         $extension = pathinfo($file_name, PATHINFO_EXTENSION);
         $upload_key = 'file' . '_' . date('YmdHis', time()) . rand(1, 9999);
         $real_key = $upload_key . '.' . $extension;
         $upload = $qiniu->uploadFile($file->getRealPath(), $real_key);
         $real_key = $upload->data['key'];
         $url = config('quickcms.qiniu_url') . '/' . $real_key;
         $ret = ['result' => true, 'key' => $upload_key, 'real_key' => $real_key, 'url' => $url, 'msg' => '上传成功'];
     } catch (Exception $e) {
         $ret = ['result' => false, 'msg' => '上传失败'];
     }
     return $ret;
 }
예제 #3
0
파일: XUpload.php 프로젝트: mgcxy/yiiSwoole
 public static function uploadToQiniu($file_path, $file_name)
 {
     //if(YII_ENV=='production'){
     Yii::import('application.vendors.Qiniu.*');
     require_once 'Qiniu.php';
     $client = \Qiniu\Qiniu::create(array('access_key' => Yii::app()->params['qiniu']['access_key'], 'secret_key' => Yii::app()->params['qiniu']['secret_key'], 'bucket' => Yii::app()->params['qiniu']['bucket']));
     $res = $client->uploadFile($file_path, $file_name);
     //}
 }