file_get_contents create file is not exists
<p>Is there any alternative to file_get_contents that would create the file if it did not exist. I am basically looking for a one line command. I am using it to count download stats for a program. I use this PHP code in the pre-download page:</p>

<pre><code>Download #: &lt;?php $hits = file_get_contents("downloads.txt"); echo $hits; ?&gt;
</code></pre>

<p>and then in the download page, I have this.</p>

<pre><code>&lt;?php
    function countdownload($filename) {
        if (file_exists($filename)) {
            $count = file_get_contents($filename);
            $handle = fopen($filename, "w") or die("can't open file");
            $count = $count + 1;
        } else {
            $handle = fopen($filename, "w") or die("can't open file");
            $count = 0; 
        }
        fwrite($handle, $count);
        fclose($handle);
    }

    $DownloadName = 'SRO.exe';
    $Version = '1';
    $NameVersion = $DownloadName . $Version;

    $Cookie = isset($_COOKIE[str_replace('.', '_', $NameVersion)]);

    if (!$Cookie) {
        countdownload("unqiue_downloads.txt");
        countdownload("unique_total_downloads.txt");
    } else {
        countdownload("downloads.txt");
        countdownload("total_download.txt");
    }

    echo '&lt;META HTTP-EQUIV=Refresh CONTENT="0; URL='.$DownloadName.'" /&gt;';
?&gt;
</code></pre>

<p>Naturally though, the user accesses the pre-download page first, so its not created yet. I do not want to add any functions to the pre download page, i want it to be plain and simple and not alot of adding/changing.</p>

<p>Edit:</p>

<p>Something like this would work, but its not working for me?</p>

<pre><code>$count = (file_exists($filename))? file_get_contents($filename) : 0; echo $count;
</code></pre>
