Why isn't file_put_contents overwriting?
<p>I have a page with a WYSIWYG editor the user can use. After editing, they can press a button, and the javascript should POST the current page to a save.php file and refresh the page with new information. </p>

<p>There are two problems. The first is that initially the page doesn't load with the updated file. The user has to refresh the page to see it updated (maybe it just takes an extra second to write the file?). The second problem, is that after the first time the temporary file was created, it cannot be overwritten, so the page never updates after the first refresh. Here are the snippets I'm working with:</p>

<p>Javascript function on the WYSIWYG editor page (editor.php):</p>

<pre><code>function refresh(html,username,info)
{
    $.post("save.php", { html: html, username: username } );
    window.location = 'editor.php?info=' + info;
}
</code></pre>

<p>save.php file</p>

<pre><code>$html = $_POST['html'];
$username = $_POST['username']; 
file_put_contents('temp/' . $username . '.txt', $html);
</code></pre>
