Re: Generating "download" pages [message #186400 is a reply to message #186399] |
Fri, 18 July 2014 15:39 |
Thomas 'PointedEars'
Messages: 701 Registered: October 2010
Karma:
|
Senior Member |
|
|
Lew Pitcher wrote:
> On response to a trigger on one web page, I want to be able to generate
> and display a new web page, /and/ at the same time, send an associated
> file as a download.
>
> The user selects (in this case) "Export recipes" (I'm developing a
> PHP/MySQL recipe management application), which causes
> 1) the page to change to a "Download in progress" page, and
> 2) a file (in this case, an XML file containing the recipes) to be sent to
> the client.
>
> Is this doable?
Yes. There are plenty of productive examples on the Web, for example when
you download from sourceforge.net and use the additional download link
(client-side scripting will trigger the download dialog automatically, but
you can cancel that).
> How do I do this with PHP?
There are several ways. Another is:
<?php
header('Content-Disposition: attachment; filename="foo.bar"'); …
header('Location: http://download.example/foo.bar');
?>
displayed content
This not just a (PHP) language feature, it is using a language-independent
HTTP feature. You can use browser developer tools to inspect the HTTP
response headers, then use the corresponding PHP functions to achieve the
same.
<http://devtoolsecrets.com/>
<http://php.net/header>
<http://tools.ietf.org/html/rfc2616>
Next time, do your homework, please.
PointedEars
--
> If you get a bunch of authors […] that state the same "best practices"
> in any programming language, then you can bet who is wrong or right...
Not with javascript. Nonsense propagates like wildfire in this field.
-- Richard Cornford, comp.lang.javascript, 2011-11-14
|
|
|