0

I have a text file in my system named "flow.txt". It is stores in my Documents folder. I want to write into this file using php. I have used following code to do this but no changes are observed in the file. It always show "Couldn't open $fp for writing!" .

 $fp = fopen('~/Documents/flow.txt', 'a') or die("Couldn't open $fp for writing!");
 fwrite($fp, print_r($arr, true));
 fclose($fp);

And also tried file_put_contents() function. But, it too didn't work. Can anyone help?

as24
  • 1
  • 2

1 Answers1

1

I would suggest three points:

  1. File path: Make sure the path is correct. Probably go to the folder Documents and command pwd to confirm it.
  2. Permission: To avoid possibility of different web server's user/group, suggest testing with permission 777 to check it: chmod 777 flow.txt in folder Documents and chmod 777 Documents in home. If it is, change back the permissions and modify the web server's (httpd?) User/Group in the configuration file.
  3. open_basedir: Check this setting referring to open_basedir - how to set for specific directory.

Hope it helps.

Community
  • 1
  • 1
drj
  • 11
  • 4