2 replies
fwrite(fopen('/home/www/coolboycsaba.freehostia.com/users/' . $_POST['username'] . '/stats.txt', 'w') or die('error'), 'content');
fclose(fopen('/home/www/coolboycsaba.freehostia.com/users/' . $_POST['username'] . '/stats.txt', 'w') or die('error'));

Is the above code correct , I have use it without variables.
And what is the fclose() function doing ?
#correct #fclose #php #syntax
  • Profile picture of the author JaguarJaguar
    You can find a lots of detail in this article:
    PHP :: Fopen And Fwrite To File.php Through Form
    {{ DiscussionBoard.errors[1726101].message }}
  • Profile picture of the author saschakimmel
    Hi,

    you should use it this way:

    if ($fp = fopen('/home/www/coolboycsaba.freehostia.com/users/' . basename($_POST['username']). '/stats.txt', 'w')) {
    fwrite($fp, 'content');
    fclose($fp);
    } else {
    die("Error!");
    }

    fclose() closes the file handle but it's just optional as PHP closes all open handles automatically when the script has finished.
    Please note that I added a basename() call for security reasons:
    PHP: basename - Manual
    Signature

    ** Get my ViralListMachine software now for free and build your own list virally by giving away free stuff @ http://www.virallistmachinegiveaway.com **

    {{ DiscussionBoard.errors[1726756].message }}

Trending Topics