PHP is_writable () returns true, but file_put_contents () returns false

I am having trouble writing to a file, although is_writable() returns true. Of course, the file exists and is apparently readable. Here is the code:

 $file = "data"; echo file_get_contents($file)."<br>"; echo is_writable($file) ? "is writable<br>" : "not writable<br>"; if (file_put_contents($file, "ghijkl", FILE_APPEND) === FALSE) echo "failed<br>"; echo file_get_contents($file)."<br>"; 

And here is the conclusion:

 abcdef is writable failed abcdef 
+6
source share
4 answers

So just need to check the free space in the file system in my case, I type the console:
df -h
File System Size Used Free Capacity Installed on
/ dev / da 0s1f 4.3G 4.0G -68M 102% / usr

free space and the file_put_contents function work after that

+1
source

Have you checked file ownership? Perhaps this is the reason, try running this code:

 chown username:groupname your_file.txt 

Remember to change the username: group_name. Hope this works for you!

0
source

Perhaps you are trying to write to a directory, not a file - that is, something that can be written, but you cannot add it. Just suppose.

0
source

You should use this:

 $file=realpath('data'); 

Then you should use this above $file in the contents placed in the file, and for the last time try specifying with a file type like (filename.filetype).

 file_put_contents($file,'fgdfgfg'); 
0
source

Source: https://habr.com/ru/post/919211/


All Articles