【发布时间】:2019-10-24 20:38:12
【问题描述】:
我正在尝试更改我的下载文件路径,以便通过添加一个不存在的文件夹“/protected/”来保持它受到保护
我的真实路径是
"/var/www/html/var/uploads/Statements/2019-06/export-1.csv"
最后我需要它:
“http://app.local:8080/protected/uploads/Statements/2019-06/export-1.csv”
我尝试了各种版本,但我的代码没有返回想要的路径。
能否帮助我编辑我的代码:
$file = realpath($file);
$projectDir = $this->container->get('kernel')->getProjectDir();
$webDir = realpath($projectDir);
$finalPath = substr($file, strlen($webDir));
$request = $this->container->get('request_stack')->getCurrentRequest();
$downloadUrl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath() . '/' . $finalPath;
return $downloadUrl;
$downloadUrl 可以正常工作,但 $finalPath 格式不正确。
【问题讨论】:
-
使用控制器并指定您需要的路由,然后将代码粘贴到控制器中并返回文件而不是 URL
标签: php symfony routing symfony-3.4