You need to get the appropriate HTTP header so that IE doesn't think
that it's an HTML page/
<?php
$filename = $_GET['filename'];
$path = "/somewhere";
/* log the download here */
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=$filename");
readfile("$path/$filename");
?>
You can also do a HTTP redirect to the file
<?php
$filename = $_GET['filename'];
$url_root = "/somewhere";
/* log the download here */
header("Location: $url_root/$filename");
?>
This is safer than the first method, as in this case the web server
controls which files the user has access to. Doing a readfile() means
having to do that yourself in order to ensure that you're not exposing
files not meant for the public (e.g. PHP files).
peetm <jg********@blueyonder.co.uk> wrote in message news:<6m********************************@4ax.com>. ..
Looking at php.net I thought this would work ...
<?php
$filename='./' . $_GET['name'];
$fp=fopen($filename, "r");
$contents = fread ($fp, filesize($filename));
fclose($fp);
@readfile($filename);
// just does the same.
//
//echo $contents;
?>
but I just get a load of garbage as a result (the binary 'made text'
really)
pemo
On Wed, 26 Nov 2003 10:49:12 GMT, peetm <jg********@blueyonder.co.uk>
wrote:
I'd like to write to a log whenever a visitor to my site downloads a
file. So, I'd like the link they click to be to a php 'page' that
returns the file. Don't know how to do that!
Side Question ...
Presumably, the dialog that you see when you download a binary (asking
for a 'Save As...' file name) is put up by your browser when it 'sees'
non-text data coming back as a response? So, how would you download a
text file - and cause this dialog to appear at the user's end?
Thanks!
pemo