This forum was down late yesterday. phpfreak went with a new forum and design.
Anyway, as far as I know you can't display anything when you're forcing a download like that. An approach is to have a page (i.e. links.php) that contains all the available download file links. Each link points to the same download script passing a parameter to identify the file that should be downloaded. i.e. a href="http://www.example.c...php?fileid=123"
The download.php script would read the "fileid" value and determine which file it is and download it through the script example you show. The users experience would be a prompt from the browser asking them were they would like to save the file locally (on their client machine) and they would remain on the links.php page.
An alternative to the filesize() problem is to read the whole file into a string. Using strlen() you would then know how big the size of the file is. You would use that size in the Content-Length header and then echo the string (containing the file contents). Another way is to simply use output buffering. Example:
$fname = 'http://www.example.com/test.txt';
header('HTTP/1.1 200 OK');
header('Content-Disposition: attachment; filename=' . basename($fname));
header('Content-Length: ' . ob_get_length());
echo 'This will not show in browser or be in file';
The above code sample will not have the echo text be in the file. However, the echo won't be displayed in the browser either (as you seem to expect). The content length cuts it off before the text.
I've tried in the past using things like 'Content-Disposition: inline; filename=xxx' and it didn't work. Also content can be sent in chunks using 'Transfer-Encoding: chunked' header and specifying the size (in hex on a separate line) of each piece of data but that hasn't worked for me either. You're welcome to play around with different headers.
I recommend you use the links.php and download.php idea/approach.
FYI: Book recommendation:
HTTP Developer's Handbook (ISBN: 0672324547) by Chris Shiflett.http://www.amazon.co...=glance&s=books
It does have a little PHP related example code, but it's mostly about the HTTP protocol itself.