简体   繁体   中英

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

I've been trying to write code to register an account in PHP. I've looked it up over and over and over again, but this problem doesn't seem to have a solution.

Here's my code:

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

You can't put contents through http like that. It would be very insecure if you could. You can only create and store file in the file system.

Since you use gethostname() , I'm assuming that you're trying to save the file on the same machine as the code.

Use a proper file path, like:

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

You might have mixed it up with file_get_contents() that can get the contents using http if you've allowed it in your php.ini.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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