Which browser are you using? IE 5.5 has a bug which causes the
syndrome you described. See this knowledge base article:
http://support.microsoft.com/default...b;en-us;303750
Check the PHP manual more info about inserting variables into strings:
http://www.php.net/manual/en/languag....syntax.double
One thing I forgot to mention in my last post is that if auto session
is on, you would need to call session_write_close() before calling
readfile(). Otherwise your visitors wouldn't be able to go to other
parts of your site while the download is occurring (as the session is
locked).
pemo <jg005b1870@blueyonder.co.uk> wrote in message news:<0bgbsvc1ecvujqvqenr6g8c7dkmasms88r@4ax.com>. ..[color=blue]
> The following (below) worked - although the 'Save As' dialog prompts
> the user to save the file as 'files' (that's the name of my php page,
> e.g.,
http://www.blah.com/files.php?name=thing.zip) and not as
> 'thing.zip' - is there anyway to correct that?
>
> (btw, I didn't know you could 'quote' a variable like that
> (readfile("$filename");) - is there any difference between
> readfile("$filename"); and readfile($filename);
>
> pemo
>
> <?php
>
> $filename='./' . $_GET['name'];
>
> /* log the download here */
>
> header("Content-type: application/octet-stream");
> header("Content-disposition: attachment; filename=$filename");
>
> readfile("$filename");
>
> ?>
>
> On 26 Nov 2003 21:38:07 -0800,
chernyshevsky@hotmail.com (Chung Leong)
> wrote:
>[color=green]
> >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 <jg005b1870@blueyonder.co.uk> wrote in message news:<6m49svkb9aonojlve7kbp60t8shnpnrnpu@4ax.com>. ..[color=darkred]
> >> 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 <jg005b1870@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[/color][/color][/color]