CHMOD 0777 and back to 0644
<p>I have a cron script that needs to write some html into a file.</p>

<p>The file that needs to have HTML written is in public_html dir and the script in a different location, just above that dir. If I CHMOD manually everything works, but I don not want to leave it as 0777 or keep on doing it manually, so I wanted to make my script to do it for me.</p>

<pre><code>ob_start();

// build my HTML

$myHTML = ob_get_clean();

// CODE TO SAVE INTO INCLUDE &lt;&lt;&lt;

$filename = 'home/public_html/file.php';

if (is_writable($filename)) {

    if (!$handle = fopen($filename, 'w')) {
         mail("support@domain.com", "Failed to create include", "Script failed to create include", "From: Support &lt;support@domain.com&gt;");
    exit;
    }

    // Write $somecontent to our opened file.
    if (fwrite($handle, ($myHTML)) === FALSE) {
       mail("support@domain.com", "Failed to create include", "Script failed to create include", "From: Support &lt;support@domain.com&gt;");
    exit;
    }

    fclose($handle);

} else {
    mail("support@domain.com", "Failed to create include", "Script failed to create include", "From: Support &lt;support@domain.com&gt;");
    exit;
}
</code></pre>

<p>Unfortunately it does not seem to work. Why?</p>
