whelpton Posted January 12, 2009 Share Posted January 12, 2009 I am trying to create a file upon sucessful user registration. I've been trying to use the following code: $filename = 'test.txt'; $somecontent = "Add this to the file\n"; // Let's make sure the file exists and is writable first. if (is_writable($filename)) { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "Success, wrote ($somecontent) to file ($filename)"; fclose($handle); } else { echo "The file $filename is not writable"; } But I'm struggling with getting the correct file location. I'm trying to use the path /home/alport/public_html/, but then also include the persons username using a variable, for example by using $_POST["username"]. But I cant get the two codes to gel together. Id greatly appreciate pointers on how to get the code working. Thanks Link to comment https://forums.phpfreaks.com/topic/140541-help-with-the-fopen-function/ Share on other sites More sharing options...
whelpton Posted January 12, 2009 Author Share Posted January 12, 2009 Anyone? Please? Link to comment https://forums.phpfreaks.com/topic/140541-help-with-the-fopen-function/#findComment-735515 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.