PHP - 写入文件根本不会输出任何内容,路径确实存在

PHP - Writing to a file won't output anything at all, path does exist

我一直在尝试编写代码在 PHP 中注册一个帐户。我翻来覆去翻了翻,这个问题好像没有解决办法。

这是我的代码:

file_put_contents("http://".strtolower(gethostname())."/member/users.txt", $_GET["username"] . "\n", FILE_APPEND);

你不能像那样把内容通过 http。如果可以,那将是非常不安全的。您只能在文件系统中创建和存储文件。

由于您使用 gethostname(),我假设您正试图将文件保存在与代码相同的机器上。

使用正确的文件路径,例如:

file_put_contents('/local/filepath/to/member/users.text', ....)

您可能将它与 file_get_contents() 混淆了,后者可以使用 http 获取内容,前提是您在 php.ini 中允许它。