简体   繁体   English

PHP中的file_put_contents

[英]file_put_contents in php

I just tried to use this file_put_contents . 我只是尝试使用此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. file_get_contents正在运行。

Update: Problem solved. 更新:问题已解决。 I'm not sure. 我不确定。 I just changed chmod to 777. But I have a doubt. 我只是将chmod更改为777。但是我对此表示怀疑。 I am checking the log error. 我正在检查日志错误。

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. 最后, file_put_contents返回写入的字节数或错误时为假的字节数。 Save the return value to a variable and see what you get back. 将返回值保存到变量中,然后看看您得到了什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM