php - Symfony: get file in controller from web folder -
i want pdf file web folder in controller, can't figure out how it.
i've try path this
// 1 $file = __dir__ . '/../../../../web/1.pdf'; // 2 $file = $this->get('kernel')->getrootdir().'\..\web\1.pdf'; // 3 $issecure = $request->issecure() ? 'https://' : 'http://'; $file = $issecure . $request->gethost() . $this->container->get('assets.packages')->geturl('1.pdf');
and use file controller helper didn't work.
how can file public directory?
try -
append autoload.php
define('application_path', realpath(__dir__) . '/'); define('web_path', application_path . '../web/');
also can add folders
then
file_get_content(web_path . 'your_file.pdf');
another way -
$path = $this->getparameter('dir.downloads');
but don't forget declare on parameters.yml this
parameters: .... dir.downloads: var/www (your folder) ....
wiki
Comments
Post a Comment