2

I need to save same temp file, now I'm using:

/**
*Magento\Framework\App\Filesystem\DirectoryList $directoryList
*/
$this->directoryList->getPath('media')

But I need same place where this files will be deleted same day.

Where is the best place to put this files?

1 Answer 1

1

I think this var

protected $_dir;
protected $_filesystem;
...

public function __construct(
    ...
    \Magento\Framework\Filesystem\DirectoryList $dir,
    \Magento\Framework\Filesystem $filesystem

    ...        
) {
    ...
    $this->_dir = $dir;
    $this->_filesystem = $filesystem;
    ...
}

public method saveFile()
{
   ...
   {
      $var = $this->filesystem->getDirectoryWrite($this->_dir->getPath('var'));
      $content = 'something';
      $var->writeFile("folder/file.txt",$content);
   }
        catch(Exception $e){
        echo $e->getMessage();
    }
   ...
}
1
  • Using this folder ('var'), when I access the file with navigator I get an error. "You don't have permission to access /mysite/var/fileName.csv on this server." Commented Jul 11, 2019 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.