本文整理汇总了PHP中Symfony\Component\HttpFoundation\BinaryFileResponse::create方法的典型用法代码示例。如果您正苦于以下问题:PHP BinaryFileResponse::create方法的具体用法?PHP BinaryFileResponse::create怎么用?PHP BinaryFileResponse::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\BinaryFileResponse
的用法示例。
在下文中一共展示了BinaryFileResponse::create方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testXSendfile
public function testXSendfile()
{
$request = Request::create('/');
$request->headers->set('X-Sendfile-Type', 'X-Sendfile');
BinaryFileResponse::trustXSendfileTypeHeader();
$response = BinaryFileResponse::create('README.md');
$response->prepare($request);
$this->expectOutputString('');
$response->sendContent();
$this->assertContains('README.md', $response->headers->get('X-Sendfile'));
}
示例2: createPrivateFileDownloadResponse
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;
}
示例3: renderFile
/**
*
*/
protected function renderFile($file, $status = 200, $headers = array(), $public = true, $contentDisposition = null, $autoEtag = false, $autoLastModified = true)
{
// Check if a output action has be already performed
$this->_checkIfPerformed();
// Create a file response
$fileResponse = \Symfony\Component\HttpFoundation\BinaryFileResponse::create($file, $status, $headers, $public, $contentDisposition, $autoEtag, $autoLastModified);
// Add request informationen
$fileResponse->prepare($this->application->requestStack->getCurrentRequest());
// Replace response object
$this->application->response = $fileResponse;
}
示例4: testAcceptRangeNotOverriden
public function testAcceptRangeNotOverriden()
{
$request = Request::create('/', 'POST');
$response = BinaryFileResponse::create(__DIR__ . '/File/Fixtures/test.gif');
$response->headers->set('Accept-Ranges', 'foo');
$response->prepare($request);
$this->assertEquals('foo', $response->headers->get('Accept-Ranges'));
}
示例5: downloadAction
public function downloadAction(Request $request, $fileId)
{
$response = new Response();
$user = $this->getCurrentUser();
if (!$user->isLogin()) {
return $this->redirect($this->generateUrl('login'));
}
$goods = $this->getThreadService()->getGoods($fileId);
$file = $this->getFileService()->getFile($goods['fileId']);
if ($goods['coin'] > 0 && $user['id'] != $file['userId']) {
$trade = $this->getThreadService()->getTradeByUserIdAndGoodsId($user['id'], $goods['id']);
if (!$trade) {
return $this->createMessageResponse('info', '您未购买该附件!');
}
}
$file = $this->getFileService()->getFile($goods['fileId']);
$this->getThreadService()->waveGoodsHitNum($goods['id']);
if (empty($file)) {
throw $this->createNotFoundException();
}
$filename = $this->get('topxia.twig.web_extension')->getFilePath($file['uri']);
$filename = substr($filename, 1);
$filename = explode("?", $filename);
$filename = $filename[0];
$response = BinaryFileResponse::create($filename, 200, array(), false);
$goods['title'] = urlencode($goods['title']);
$goods['title'] = str_replace('+', '%20', $goods['title']);
if (preg_match("/MSIE/i", $request->headers->get('User-Agent'))) {
$response->headers->set('Content-Disposition', 'attachment; filename="' . $goods['title'] . '"');
} else {
$response->headers->set('Content-Disposition', "attachment; filename*=UTF-8''" . $goods['title']);
}
$response->headers->set('Content-type', "application/octet-stream");
return $response;
}
示例6: getLocalVideo
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;
}
示例7: serveImageAction
/**
* Serve the image from the templates-folder
* @param string $filename
* @param string $folderKey
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse
*/
public function serveImageAction($folderKey, $filename)
{
$folder = $this->getTemplateProviderService()->getFolderFrom($folderKey);
if ($folder !== false) {
$fullPath = $folder . $filename;
$response = BinaryFileResponse::create($fullPath);
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE);
$response->headers->set("Content-Type", "image");
return $response;
}
throw new FileNotFoundException($filename);
}
示例8: pageImageAction
/**
* @param Request $request
* @param Document $document
* @param int $page
* @param string $size
* @throws \RuntimeException
* @return Response
*/
public function pageImageAction(Request $request, Document $document, $page, $size)
{
$sizes = array('small' => 180, 'normal' => 700, 'large' => 1000);
$width = $sizes[$size];
$destination = realpath($this->container->getParameter('kernel.root_dir') . '/../web') . $request->getPathInfo();
/** @var \Bangpound\Bundle\DocumentCloudBundle\BinaryDriver\GraphicsmagickDriver $driver */
$driver = $this->get('bangpound_documentcloud.binary_driver.graphicsmagick');
$filesystem = $this->get('filesystem');
$filesystem->mkdir(dirname($destination));
$arguments = array('convert', '+adjoin', '-define', 'pdf:use-cropbox=true', '-limit', 'memory', '256MiB', '-limit', 'map', '512MiB', '-density', '150', '-resize', $width . 'x', '-quality', 100, $document->getAbsolutePath() . '[' . ($page - 1) . ']', $destination);
$builder = $driver->getProcessBuilderFactory();
$process = $builder->create($arguments);
$process->setEnv(array('PATH' => getenv('PATH')));
$process->run();
if (!$process->isSuccessful()) {
throw new \RuntimeException($process->getErrorOutput());
}
return BinaryFileResponse::create($destination);
}
示例9: localMediaAction
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;
}