Пример #1
0
 /**
  * 分享文件
  * POST /share/
  * @method POST_index
  * @param key 获取token时返回的key
  */
 public function POST_indexAction()
 {
     $userid = $this->auth();
     $response['status'] = 0;
     if (!Input::post('fid', $fid, 'int')) {
         $response['info'] = '未选择文件';
     } elseif (!($File = FileModel::field('name,url,status')->where('use_id', '=', $userid)->where('status', '>', 0)->find($fid))) {
         /*数据库中查询的文件*/
         $response['info'] = '文件无效';
     } elseif ($File['status'] & self::SHARED_FLAG) {
         /*是否已经共享*/
         $response['info'] = '文件已分享';
     } elseif (!($share['url'] = File::share($File->url))) {
         /*发布到共享空间*/
         $response['info'] = '文件转移出错';
     } else {
         /*验证完成,开始插入*/
         $share['fil_id'] = $fid;
         $share['use_id'] = $userid;
         $share['name'] = Input::post('name', $name, 'title') ? $name : $File->name;
         if (Input::post('detail', $detail, 'text')) {
             $share['detail'] = $detail;
         }
         if (Input::post('anonymous', $anonymous)) {
             $share['anonymous'] = boolval($anonymous);
         }
         if ($sid = ShareModel::Insert($share)) {
             //插入成功
             //文件状态,更新为已分享
             $File->save(['status' => $File['status'] | self::SHARED_FLAG]);
             //TODO
             //分享文件预处理
             $response['status'] = 1;
             $response['info'] = ['msg' => '分享成功', 'id' => $sid];
         } else {
             $response['info'] = '分享失败';
         }
     }
     $this->response = $response;
 }