How to authenticate users before downloading files?
<p>For example, if users want to download /webroot/files/bigimage.jpg, they are given a URL www.domain.com/download.php?filename=bigimage.jpg. Then,</p>

<ol>
<li>How to prevent unauthenticated users
to access the file bigimage.jpg?</li>
<li>If an authenticated user visits that
URL, I want to trigger the download
behavior of browsers (e.g., in IE,
show the dialog with "Open", "Save"
and "Cancel" buttons) instead of
displaying the image in browsers.
How to do this?</li>
</ol>

<p>EDIT: 
Make the question more clearer.</p>

<p>I am using LAMP stack. For Q1, I am not asking how to do authentication, I am asking how to prevent users access the file directly. Also, reading contents of the whole file and echo them is resource extensive. Is there better solution?</p>
