I am trying to remove a file from folder using remove function of the filesystem component in Symfony 4.
Here is my code in the controller:
//Get old logo
$oldlogo = $employer->getLogo();
//If there is a old logo we need to detele it
     if($oldlogo){
       $filesystem = new Filesystem();
       $path=$this->getTargetDirectory().'/public/uploads/logos/'.$oldlogo;
       $filesystem->remove($path);
 }
private $targetDirectory;
public function __construct($targetDirectory)
    {
        $this->targetDirectory = $targetDirectory;
    }
public function getTargetDirectory()
    {
        return $this->targetDirectory;
    }
Service.yalm:
parameters:
    logos_directory: '%kernel.project_dir%/public/uploads/logos'
App\Controller\EmployerController:
        arguments:
            $targetDirectory: '%logos_directory%'
I have no error message but the file not deleted from the folder.
 
                        
I using this solution:
in my services.yaml I add:
and in my controller I use