Symfony2:如何强制下载
我正在尝试制作一个链接,下载一个带有symfony2的文件。它确实下载了一个文件,但它是没有用的,因为它是零八位元。我不知道该怎么做。有人知道怎么做吗 该文件位于Symfony2:如何强制下载,symfony,download,Symfony,Download,我正在尝试制作一个链接,下载一个带有symfony2的文件。它确实下载了一个文件,但它是没有用的,因为它是零八位元。我不知道该怎么做。有人知道怎么做吗 该文件位于web/uploads/documents/中 以下是控制器中的代码: // here I get the name of the file $response = new Response(); $response->headers->set('Content-type', 'application/octet-
web/uploads/documents/
中
以下是控制器中的代码:
// here I get the name of the file
$response = new Response();
$response->headers->set('Content-type', 'application/octet-stream');
$response->headers->set('Content-Disposition', sprintf('attachment; filename="%s"', $filename));
return $response;
我尝试编写整个路径而不是
$filename
,但它更改了下划线中的所有斜杠。您忘记设置内容:
$response->setContent(file_get_contents($localFilePath));
您忘记设置内容:
$response->setContent(file_get_contents($localFilePath));