'Unable to open file in ubuntu

I wrote my code in windows OS with xampp: code to create txt file and download.

It works correctly.

When I use the same code on ubuntu server it's not working: message --"Unable to open file!"--

<?php  

$file = "www.txt";
$txt = fopen($file, "w") or die("Unable to open file!");
fwrite($txt,
"
anything to write ");
fclose($txt);

header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename='.basename($file));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
header("Content-Type: text/plain");
readfile($file);  ?>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source