Skip to main content

Magento2 Framwork to deal with files/directories

To work with files in Magento2 you should follow the Framework rules, below are set of command we can use for each PHP command


class name \Magento\Framework\Filesystem\Io\File;
another class can be usefull as well 

file_exist()        => $this->file->fileExists($file);
unlink()        => $this->file->rm($file)
mkdir()            => $this->file->mkdir($dir)
dirname()        => $this->file->dirname($file)
file_put_contents()    =>$this->file->write($filename, $src, $mode)