I have the following code:
<?php
$myfile = fopen("code2.css", "w") or die("Unable to open file!");
$txt = "John Doe\n";
fwrite($myfile, $txt);
$txt = "Jane Doe\n";
fwrite($myfile, $txt);
fclose($myfile);
?>
?>
code2.css is in the same folder as my PHP file, but it throws me:
Unable to open file all the time.
How can I fix this?
Update: After playing with permissions the error dissapeared, but still my file won't be updated.
Check the properties of code2.css. You must found the "read only" permission to it, and change it to "Read and Write". After that your code will work.
If you are using a Linux system, then execute:
sudo chmod 777 code2.css
<?php
$myfile = fopen("code2.css", "w") or die("Unable to open file!");
$txt = "John Doe\n";
fwrite($myfile, $txt);
$txt = "Jane Doe\n";
fwrite($myfile, $txt);
fclose($myfile);//just removed the closing php tag from here and it is working fine
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With