public function uploadFile() { $request = Request::capture(); $file = $request->file('file'); $fileName = $request->input('filename'); $width = $request->input('width'); $height = $request->input('height'); if ($file->isValid()) { $tmpName = $file->getFilename(); $realPath = $file->getRealPath(); $extension = $file->getClientOriginalExtension(); $fileType = $file->getMimeType(); } $picURL = 'urla-------'; /* $client = S3Client::factory(array( 'region' => 'us-west-2', 'version' => 'latest', 'credentials' => [ 'key' => 'AKIAICY5UKOXG57U6HGQ', 'secret' => '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', ], )); $s3key = 'tempKey'; $result = $client->putObject(array( 'ACL' => 'public-read', 'Bucket' => 'questionbucket', 'Key' => $s3key, 'SourceFile' => $realPath )); $picURL = $result['ObjectURL']; */ try { $picture = Picture::create(['original_pic' => $picURL, 'bmiddle_pic' => $picURL, 'thumbnail_pic' => $picURL, 'pictureName' => $fileName, 'width' => $width, 'height' => $height]); return Utility::response_format(Utility::RESPONSE_CODE_SUCCESS, $picture->getAttributes(), '上传成功'); } catch (Exception $e) { return Utility::response_format(Utility::RESPONSE_CODE_DB_ERROR, '', $e->getMessage()); } }
public function getAnswerDetail() { $request = Request::capture(); $token = $request->input('token'); $answerId = $request->input('answerId'); $userId = AuthController::getUserIdByToken($token); if ($userId == null) { return Utility::response_format(Utility::RESPONSE_CODE_AUTH_ERROR, '', '认证失败'); } if ($answerId == null) { return Utility::response_format(Utility::RESPONSE_CODE_Error, '', 'answerId不能为空'); } $answer = Answer::select('id', 'answer_content', 'answer_time', 'question_id', 'user_id', 'is_resolved')->where('id', $answerId)->first()->toArray(); // print_r($question); // 个人信息 $userInfo = UserInfo::select('user_name', 'head_pic')->where('user_id', $answer['user_id'])->first()->toArray(); $answer = array_merge($answer, $userInfo); // 图片 $picIds = AnswerPictures::select('pic_id')->where('answer_id', $answer['id'])->get()->toArray(); $pics = Picture::whereIn('id', $picIds)->get()->toArray(); $answer = array_merge($answer, ['image' => $pics]); // 评论数 $comments = Comment::where('answer_id', $answer['id'])->count(); $answer = array_merge($answer, ['commentNumber' => $comments]); // 赞数 $upCount = AnswerUp::where('answer_id', $answer['id'])->count(); $answer = array_merge($answer, ['upNumber' => $upCount]); return Utility::response_format(Utility::RESPONSE_CODE_SUCCESS, $answer, '请求成功'); }