file_get_contents creating an empty file
<p>how can I prevent file_get_contents from creating an empty file when being used as a test condition in an if clause?</p>

<p>An empty file is created regardless, which causes a subsequent call in a different method to getimagesize() to fail.</p>

<p>The problem is, that as I have my code setup, the first time it is called will determine to save an image or to display a previously saved imaged. This is in part dependent on the presence of a file. As an empty file is created, this causes problems when calling my code subsequent times.</p>

<p>Is the easiest way to add a check if the file exists and is greater than 0?</p>

<p>Regardless of if my code works, file_get_contents will still output an error. This error is accounted for and dealt with(by my if condition), so I would like to avoid the error interrupting the output of my application if possible. Is there a way to turn this off without hiding actual errors?</p>

<pre><code>if (file_put_contents($imageDir . $pk . '.jpg', file_get_contents($pic_url))) 
{
        return $imageDir . $pk . '.jpg'; 
} 
else 
{
        return 'removed.jpg';
}
</code></pre>
