Why Symfony File Upload path always begins with /public folder when using getenv()?

Viewed 20

This is my code:

.env file:

UPLOAD_PATH=".var/uploads/docs"

MyController.php

$destination = getenv('UPLOAD_PATH');
/** @var UploadedFile $uploadedFile */
$uploadedFile = $form['file']->getData();
dump($uploadedFile->move($destination, $uploadedFile->getClientOriginalName()));

The dump output:

  pathname: "./var/uploads/docs/test.txt"
  realPath: "/var/www/html/public/var/uploads/docs/test.txt"

Actually my intention is to save it in var folder but it always ends up in public/var... every path I enter no matter how and what end up in public folder.

However when I try this it works fine:

$destination = $this->getParameter('kernel.project_dir').'/var/uploads/docs';

I want to use the first way with getenv and .env, is there any way to make it work and upload files to desired folder?

0 Answers
Related