The file_system service

If you need to interact directly with files on the system, you will need to use the file_system service. If you are creating files for media, you will probably want to use the Media entity, this is only for direct file manipulation needed in some other cases, usually custom code.

The file_system services uses the FileSystem class: core/lib/Drupal/Core/File/FileSystem.php.

To create a new directory, use prepareDirectory:

$file_system->prepareDirectory(
  $directory, \Drupal\Core\File\FileSystemInterface::CREATE_DIRECTORY | \Drupal\Core\File\FileSystemInterface::MODIFY_PERMISSIONS);

 

Tags
Files