简体   繁体   中英

Symfony: Web directory path

I have uploaded PDF file in web directory. I get that files as shown below:

$webPath = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/foldername/';

$filename = $webPath . $finddata->getUploadedFileName();
$filename = str_replace("\\", '/', $filename);

It gives me path as below:

D:/xampp/htdocs/projectname/app/../web/uploads/foldername/filename

But I want http path of it.

Can any body help me for this to get http path?

Try below

$isSecure = $request->isSecure() ? 'https://' : 'http://';
$fileName = $isSecure . $this->getRequest()->getHost() . $this->container->get('templating.helper.assets')->getUrl('uploads/foldername/filename.pdf');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM