草庐IT

BinaryFileResponse

全部标签

PHP Symfony2 : Delete a temp file after response

我有一个生成图像并在响应中返回图像的Controller。useFOS\RestBundle\Controller\AnnotationsasRest;useSymfony\Component\HttpFoundation\BinaryFileResponse;.../***@Rest\Get("/image/{name}")*/publicfunctiongetImage($name){$imageService=$this->get('image.service');$tempImage=$imageService->genImage($name);returnnewBinaryF

php - Laravel 中的 BinaryFileResponse 未定义

我遇到了以下问题:我想在路线/getImage/{id}上返回一个图像函数如下所示:publicfunctiongetImage($id){$image=Image::find($id);returnresponse()->download('/srv/www/example.com/api/public/images/'.$image->filename);}当我这样做时,它会返回给我:FatalErrorExceptioninHandleCors.phpline18:CalltoundefinedmethodSymfony\Component\HttpFoundation\Bina

php - Laravel 中的 BinaryFileResponse 未定义

我遇到了以下问题:我想在路线/getImage/{id}上返回一个图像函数如下所示:publicfunctiongetImage($id){$image=Image::find($id);returnresponse()->download('/srv/www/example.com/api/public/images/'.$image->filename);}当我这样做时,它会返回给我:FatalErrorExceptioninHandleCors.phpline18:CalltoundefinedmethodSymfony\Component\HttpFoundation\Bina

php - Symfony BinaryFileResponse 设置文件名

当Symfony2Controller使用BinaryFileResponse响应返回文件时,是否可以设置自定义文件名? 最佳答案 是的。BinaryFileResponse类有一个方法setContentDisposition(),它将文件名作为第二个参数。第一个参数是传递文件的方式。它可以是ResponseHeaderBag::DISPOSITION_ATTACHMENT(或只是字符串"attachment")如果文件应该被提供下载,或者ResponseHeaderBag::DISPOSITION_INLINE(或“inline