Imran Abdur Rahim
Imran Abdur Rahim

Reputation: 417

file_put_contents in php

I just tried to use this file_put_contents. The code is:

$file = 'list.txt';
$subject = "Mail Subject\n";
file_put_contents($file, $subject);

But it doesn’t put any contents. file_get_contents is working though.

Update: Problem solved. I’m not sure. I just changed chmod to 777. But I have a doubt. I am checking the log error.

Upvotes: 0

Views: 2550

Answers (1)

Jim OHalloran
Jim OHalloran

Reputation: 5918

Things to check:

  • Your file path is relative. So your file may not be in the directory you think it is.
  • Check that you have permission to create files in the directory containing your file, or that you have permissions to overwrite the existing file.
  • Finally, file_put_contents returns the number of bytes written or false on error. Save the return value to a variable and see what you get back.

Upvotes: 1

Related Questions