My code is
<?php
$fp = fopen('test.txt', "a+");
fwrite($fp, 'Cats chase mice');
fclose($fp);
?>
but test.txt is still empty. I don't see anything wrong and I don't understand why it's not writing.
My code is
<?php
$fp = fopen('test.txt', "a+");
fwrite($fp, 'Cats chase mice');
fclose($fp);
?>
but test.txt is still empty. I don't see anything wrong and I don't understand why it's not writing.
Write this in a console
This is a file permissions issue.
This will chmod your file to
777
making it writeable.Tested on Linux server:
You can also use
0666
or0644
depending on how high a permission you wish the file to have, yet0644
would be your safest option; see below.You can also type in
chmod 777 test.txt
orchmod 666 test.txt
orchmod 644 test.txt
via FTP.My server let's me use
0644
to write and append to and may be different on the server you are wanting to execute your code.Quoted from http://www.centos.org/docs/2/rhl-gsg-en-7.2/s1-navigating-chmodnum.html
Beware 666 and 777
Setting permissions to 666 or 777 will allow everyone to read and write to a file or directory.
These permissions could allow tampering with sensitive files, so in general, it is not a good idea to use these settings.
Here is a list of some common settings, numerical values and their meanings:
Here are some common settings for directories: