php: forcedownload on my own server - check if file exists?
<p>hey guys,
i'm using a force-download script on my own server. - click on  a link and the file prompts as download. works perfect, but even if a file does not exist it can be downloaded as empty file. so if i set a link with /folder/filexyz.txt it prompts the download and an empty txt-file gets downloaded to the harddrive.</p>

<p>i'm currently using this script:</p>

<pre><code>header("Cache-Control: no-cache");
header("Expires: -1");
header("Content-Type: application/octet-stream;");
header("Content-Disposition: attachment; filename=\"" . basename($file) . "\";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . filesize($file));
echo readfile($file);
</code></pre>

<p>$file is the complete path to my file like: <a href="http://www.mydomain.com/folder1/folder2/folder/filexyz.txt" rel="nofollow">http://www.mydomain.com/folder1/folder2/folder/filexyz.txt</a></p>

<p>how can i check if the file exists or not. If it's not there the download should not prompt, otherwise of course yes.</p>
