I have the following code:
protected $_fileSystem;
protected $_directoryList;
public function __construct(
\Magento\Framework\Filesystem $fileSystem,
\Magento\Framework\App\Filesystem\DirectoryList $directoryList
) {
$this->_fileSystem = $fileSystem;
$this->_directoryList = $directoryList;
parent::__construct($context);
}
public function execute(){
$this->writeToCSV();
}
private function writeToCSV(){
try{
$media = $this->_fileSystem->getDirectoryWrite($this->_directoryList::MEDIA);
$media->writeFile('text.txt', 'test');
}
catch(Exception $e){
echo($e->getMessage());
}
}
However, this doesn't seem to be writing anything to the text file that exists within the same folder as the controller.