Skip to main content

any times you need to interact with files in your modules or coding. 

In this article we will mention the most important functions that Drupal provides out of the box.

Private and Public paths

Get public uri:

use Drupal\Core\StreamWrapper\PrivateStream;
use Drupal\Core\StreamWrapper\PublicStream;


Get the real path of public uri: 


Get private uri: 


And real path for private uri: 


You would need to set private file path in settings.php as :

$settings['file_private_path'] = 'sites/default/private';

And this directory must exists and writable by web server (www-data).