Is this correct ?

by 2 replies
3
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 ?
#programming #correct #fclose #php #syntax
  • You can find a lots of detail in this article:
    PHP :: Fopen And Fwrite To File.php Through Form
  • 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

Next Topics on Trending Feed

  • 3

    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'));