0

i complete my code on windows xampp to download text(or other file) file and its work good but when i upload the code on ubuntu server its does not work can you help me plz

$file = "$username.rsc";
$txt = fopen($file, "w") or die("Unable to open file!");
fwrite($txt,
"{
anything
}

");
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');
  ob_clean();
    flush();
header('Content-Length: ' . filesize($file));
header("Content-Type: text/plain");
readfile($file);

the response on ubuntu is Unable to open file!

Samathingamajig
  • 11,839
  • 3
  • 12
  • 34

1 Answers1

0

This sounds like a permissions issue. Make sure that your Apache user and group has access to the file and directory that you are trying to modify.

Ervin Šabić
  • 115
  • 3
  • 14
  • in: /var/www/html$ls -la what should i do ? – Mohammed Al-Aazawy Apr 24 '22 at 21:05
  • @MohammedAl-Aazawy whats the output of `ls -l` inside your project directory? In Ubuntu I believe the default apache user is `www-data` so as a temp fix you could use `chown www-data:www-data ./* -R` **INSIDE OF YOUR PROJECT DIRECTORY**. Make sure you check to see who the current user and group is that way you can revert it back should something go wrong. – Ervin Šabić Apr 24 '22 at 21:09
  • drwxrwxrwx 5 sinan www-data 4096 Apr 22 12:31 . – Mohammed Al-Aazawy Apr 24 '22 at 21:25
  • Check this answer out: https://stackoverflow.com/questions/2900690/how-do-i-give-php-write-access-to-a-directory – Ervin Šabić Apr 24 '22 at 21:28