protected function createPrivateFileDownloadResponse(Request $request, $file) { $response = BinaryFileResponse::create($file['fullpath'], 200, array(), false); $response->trustXSendfileTypeHeader(); $file['filename'] = urlencode($file['filename']); if (preg_match("/MSIE/i", $request->headers->get('User-Agent'))) { $response->headers->set('Content-Disposition', 'attachment; filename="' . $file['filename'] . '"'); } else { $response->headers->set('Content-Disposition', "attachment; filename*=UTF-8''" . $file['filename']); } $mimeType = FileToolkit::getMimeTypeByExtension($file['ext']); if ($mimeType) { $response->headers->set('Content-Type', $mimeType); } return $response; }
public function getLocalVideo() { $fileId = $this->getParam("targetId"); $user = $this->controller->getuserByToken($this->request); if (!$user->isLogin()) { return $this->createErrorResponse('not_login', "您尚未登录!"); } $file = $this->getUploadFileService()->getFile($fileId); if (empty($file)) { return $this->createErrorResponse('error', "视频文件不存在!"); } $response = BinaryFileResponse::create($file['fullpath'], 200, array(), false); $response->trustXSendfileTypeHeader(); $mimeType = FileToolkit::getMimeTypeByExtension($file['ext']); if ($mimeType) { $response->headers->set('Content-Type', $mimeType); } return $response; }
public function localMediaAction(Request $request, $id, $token) { $file = $this->getUploadFileService()->getFile($id); if (empty($file)) { throw $this->createNotFoundException(); } if (!in_array($file["type"], array("audio", "video"))) { throw $this->createAccessDeniedException(); } $token = $this->getTokenService()->verifyToken('local.media', $token); if ($token['userId'] != $this->getCurrentUser()->getId()) { throw $this->createAccessDeniedException(); } $response = BinaryFileResponse::create($file['fullpath'], 200, array(), false); $response->trustXSendfileTypeHeader(); $mimeType = FileToolkit::getMimeTypeByExtension($file['ext']); if ($mimeType) { $response->headers->set('Content-Type', $mimeType); } return $response; }