What are some alternative methods, besides PHP, for managing files outside of the web root directory on a server?

When managing files outside of the web root directory on a server, it is important to ensure that the files are not accessible to the public. One way to do this is by using PHP to handle file management tasks. However, there are alternative methods that can be used such as using server-side languages like Python, Ruby, or Node.js, or using server configurations like .htaccess rules to restrict access to specific directories.

// Example of using PHP to manage files outside of the web root directory

$filePath = '/path/to/external/directory/file.txt';

// Read file
$fileContent = file_get_contents($filePath);

// Write to file
file_put_contents($filePath, 'New content');

// Delete file
unlink($filePath);