FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Generating "download" pages
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Generating "download" pages [message #186399] Fri, 18 July 2014 13:55 Go to next message
Lew Pitcher is currently offline  Lew Pitcher
Messages: 60
Registered: April 2013
Karma: 0
Member
I'm not certain that what I want can be done, let alone done with PHP, but
please let me describe the function I'm looking for:


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? How do I do this with PHP?

--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request
Re: Generating "download" pages [message #186400 is a reply to message #186399] Fri, 18 July 2014 15:39 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
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
Re: Generating "download" pages [message #186402 is a reply to message #186400] Sat, 19 July 2014 15:38 Go to previous messageGo to next message
Lew Pitcher is currently offline  Lew Pitcher
Messages: 60
Registered: April 2013
Karma: 0
Member
Thanks for the response, Thomas.

Next time, please contain your snark. It ill suits you.

On Friday 18 July 2014 11:39, in comp.lang.php, "Thomas 'PointedEars' Lahn"
<PointedEars(at)web(dot)de> wrote:

> 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)

I can, by viewing the source of web pages that use multiple javascript files
with intentionally convoluted logic, and filtering out (in a masterly way)
all that extraneous stuff, find that the web page in question (such as the
download page for a sourceforge project) does *not* include the "server
side" logic that does this. I can /then/ examine the headers from such a
working page, *deduce* that the page sent both html
and "Content-Disposition" (etc.) headers, and *assume* the method of
generating such.

Indeed, this is how I've done it in the past, with poor results.


>> How do I do this with PHP?
>
> There are several ways. Another is:

And, the first was?

>
> <?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.

But, to set headers, you need some sort of active language. Mine is PHP..

> You can use browser developer tools to inspect the HTTP
> response headers, then use the corresponding PHP functions to achieve the
> same.

Or, I can ask in a forum that specializes in such programming, and save
myself the blind alleys, false starts, and mis-assumptions that such an
inspection of the outside effects would bring

[snip suggested tools]


>
> Next time, do your homework, please.

Condescending, no?

In fact, I've done my homework. And *this* is part of that homework.

Thomas, either be helpful or don't reply. Such snark is not helpful.
--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request
Re: Generating "download" pages [message #186403 is a reply to message #186400] Sat, 19 July 2014 15:58 Go to previous messageGo to next message
Lew Pitcher is currently offline  Lew Pitcher
Messages: 60
Registered: April 2013
Karma: 0
Member
On Friday 18 July 2014 11:39, in comp.lang.php, "Thomas 'PointedEars' Lahn"
<PointedEars(at)web(dot)de> wrote:

> 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.
>>
[snip]
>> 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
[snip]

Now, having tried your suggested solution, I must tell you that *it did not
work*. So much for /your/ advice.

Here's the PHP I wrote:
<?php
header('Content-Disposition: attachment; filename="SixSpot_d.png');
header('Location: http://merlin.puter.lan/~lpitcher/SixSpot_d.png');
?>
<html>
<head><title>Trial Sendfile</title></head>
<body>
<p>Did you get it?</p>
</body>
</html>

There exists, in the source directory, a PNG file named "SixSpot_d.png.
That file can be accessed through the (internal) url
http://merlin.puter.lan/~lpitcher/SixSpot_d.png'

The web page, above, fails to initiate a download or show the specified web
page.

Instead, the web browser (Firefox 5.0.1 for Linux) /displays/ the specified
PNG, instead of the specified html, and /does not/ initiate either an
automatic download into the configured download directory or the Download
menu itself.

Advice (from various sources including PHP.NET) conflict as to which headers
are required, and the order of steps to perform.

So, Thomas, got any more "advice" for me?
--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request
Re: Generating "download" pages [message #186404 is a reply to message #186399] Sat, 19 July 2014 16:17 Go to previous messageGo to next message
Arno Welzel is currently offline  Arno Welzel
Messages: 317
Registered: October 2011
Karma: 0
Senior Member
Lew Pitcher, 2014-07-18 15:55:

> I'm not certain that what I want can be done, let alone done with PHP, but
> please let me describe the function I'm looking for:
>
>
> 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? How do I do this with PHP?

I would solve it this way:

A PHP script displays the page *and* also generates a
META-Refresh-Header to redirect the browser to another script (or the
same whith an additional parameter) which will then generate the content
to be downloaded.

As a rough example (untested and not complete - just to get the idea):

<?php
//
// getfile.php
//

if(!isset($_GET['download'))
{
?>
<!DOCTYPE html>
<html>
<head>
<meta
http-equiv="refresh"
content="5; url=http://example.com/getfile.php?download=1" />
<title>Download</title>
</head>
<body>
<p>If your download does not start automatically,
<a href="http://example.com/getfile.php?download=1">click here</a>.</p>
</body>
</html>
<?
}
else
{
header("Content-Disposition: attachment; filename=download.xml");

// Add XML output to be downloaded here...
}
?>


--
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
http://fahrradzukunft.de
Re: Generating "download" pages [message #186405 is a reply to message #186399] Sat, 19 July 2014 16:25 Go to previous messageGo to next message
Lew Pitcher is currently offline  Lew Pitcher
Messages: 60
Registered: April 2013
Karma: 0
Member
I will elaborate on the processing I'm trying to perform:

On Friday 18 July 2014 09:55, in comp.lang.php, "Lew Pitcher"
<lew(dot)pitcher(at)digitalfreehold(dot)ca> wrote:

> I'm not certain that what I want can be done, let alone done with PHP, but
> please let me describe the function I'm looking for:
>
>
> 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.

I already have a working PHP/MySQL/HTML page that permits the end user to
refine a list of known recipes by various criteria. This same page provides
options, once the user has adequately refined the recipe list, to View a
single recipe, or to Export all the selected recipes. It is this Export
function that I am now designing.

Conceptually, if the user selects the "Export" option on the menu page, the
browser would display an "Export Options" page that lists the various
export formats the selected recipes can be saved as. Initially, this would
include PDF (for offline viewing or printing), and as a recipe interchange
file (possibly a MealMaster file, although I would like to include to a
custom XML representation as well.

On this "Export Options" page, the user will
1) select the appropriate option, and then
2) select the "Send" button

The PHP behind this page will then
a) build the appropriate transport format file
b) send the file to the user, and
c) resend the "Export Options" page.

From the users POV, he
a) sees the initial "Export Options" page,
b) selects the requisite transport format for the selected recipes,
c) selects the "Send" button,
d) sees a redisplayed "Export Options" page, and
e) sees a file (of appropriate type) downloading (or the browsers Download
menu, if default download options have not been set)
At this point, the user can then either select a new transport format, and
go through the process again, or select a "Return to Menu" option that
redirects to the menu PHP file.


> Is this doable? How do I do this with PHP?

Research has shown conflicting advice wrt the necessary headers, the order
of the headers, the presence or absence of the web page HTML, the PHP
functions required to send the file, etc.

--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request
Re: Generating "download" pages [message #186406 is a reply to message #186405] Sat, 19 July 2014 16:36 Go to previous messageGo to next message
Tim Streater is currently offline  Tim Streater
Messages: 328
Registered: September 2010
Karma: 0
Senior Member
In article <b_wyv.50770$OC3(dot)15102(at)fx18(dot)iad>, Lew Pitcher
<lew(dot)pitcher(at)digitalfreehold(dot)ca> wrote:

> Research has shown conflicting advice wrt the necessary headers, the order
> of the headers, the presence or absence of the web page HTML, the PHP
> functions required to send the file, etc.

Here's what I do to send a file:

<?php

$file = '/path/to/somefile.zip';

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize ($file));

ob_clean ();
flush ();
readfile ($file);

?>

and this works for me. The file containing this PHP is the action of a
<form> which is submitted when the user clicks a button.

--
"The idea that Bill Gates has appeared like a knight in shining armour to
lead all customers out of a mire of technological chaos neatly ignores
the fact that it was he who, by peddling second-rate technology, led them
into it in the first place." - Douglas Adams
Re: Generating "download" pages [message #186407 is a reply to message #186403] Sat, 19 July 2014 17:06 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
Lew Pitcher wrote:

> So, Thomas, got any more "advice" for me?

When you are ready to communicate in a civilized manner.


PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Re: Generating "download" pages [message #186408 is a reply to message #186400] Sat, 19 July 2014 17:43 Go to previous messageGo to next message
Christoph Michael Bec is currently offline  Christoph Michael Bec
Messages: 207
Registered: June 2013
Karma: 0
Senior Member
Thomas 'PointedEars' Lahn 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.
>>
>> 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

How is that supposed to work? HTTP can only deliver a single response,
and AFAIK there is no such thing as multipart responses for HTTP.

Anyway, I have tried that idea, and that confirmed my presumption that
the browser is redirected to the Location URI, but the "displayed
content" is not shown.

Using a Refresh header instead of Location might work, but on one hand
the Refresh is not part of the HTTP/1.1 specification (CMIIW), and on
the other the effect is not exactly what the OP asked for. It seems to
me the only way to get this behavior would be in combination with client
side scripting, what would be on-topic for comp.lang.javascript, for
instance.

--
Christoph M. Becker
Re: Generating "download" pages [message #186409 is a reply to message #186406] Sat, 19 July 2014 17:53 Go to previous messageGo to next message
Lew Pitcher is currently offline  Lew Pitcher
Messages: 60
Registered: April 2013
Karma: 0
Member
On Saturday 19 July 2014 12:36, in comp.lang.php, "Tim Streater"
<timstreater(at)greenbee(dot)net> wrote:

> In article <b_wyv.50770$OC3(dot)15102(at)fx18(dot)iad>, Lew Pitcher
> <lew(dot)pitcher(at)digitalfreehold(dot)ca> wrote:
>
>> Research has shown conflicting advice wrt the necessary headers, the
>> order of the headers, the presence or absence of the web page HTML, the
>> PHP functions required to send the file, etc.
>
> Here's what I do to send a file:
>
> <?php
>
> $file = '/path/to/somefile.zip';
>
> header('Content-Description: File Transfer');
> header('Content-Type: application/octet-stream');
> header('Content-Disposition: attachment; filename=' . basename($file));
> header('Content-Transfer-Encoding: binary');
> header('Expires: 0');
> header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
> header('Pragma: public');
> header('Content-Length: ' . filesize ($file));
>
> ob_clean ();
> flush ();
> readfile ($file);
>
> ?>
>
> and this works for me. The file containing this PHP is the action of a
> <form> which is submitted when the user clicks a button.
>

Thanks, Tim, but this doesn't work for me, and seems to have problems in
general.

Instead of getting a refreshed web page (containing new content, as per the
PHP processing of the $_POST data) /and/ a (in this case PNG) file
downloading, I get a display of the PNG file (as if it had been imbedded in
it's own webpage) and nothing else.

A critique (elsewhere) of this sort of code points out
* Content-Description is not a valid HTTP header
(not mentioned at all in RFC 2616)
* Content-Type should be set to the actual media type, or none at all.
* The code for Content-Disposition will produce incorrect headers for many
filenames.
* Content-Transfer-Encoding is not a valid HTTP header (explicitly specified
in RFC 2616 pp 19.4.5 "No Content-Transfer-Encoding")

I realize that this code comes almost directly from PHP.NET, being
documented in the "manual" page for readfile(). But, that doesn't mean that
it is correct, or even that it works.

Sorry, but it looks like I have to keep trying.
--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request
Re: Generating "download" pages [message #186410 is a reply to message #186409] Sat, 19 July 2014 18:14 Go to previous messageGo to next message
Lew Pitcher is currently offline  Lew Pitcher
Messages: 60
Registered: April 2013
Karma: 0
Member
On Saturday 19 July 2014 13:53, in comp.lang.php, "Lew Pitcher"
<lew(dot)pitcher(at)digitalfreehold(dot)ca> wrote:

> On Saturday 19 July 2014 12:36, in comp.lang.php, "Tim Streater"
> <timstreater(at)greenbee(dot)net> wrote:
>
>> In article <b_wyv.50770$OC3(dot)15102(at)fx18(dot)iad>, Lew Pitcher
>> <lew(dot)pitcher(at)digitalfreehold(dot)ca> wrote:
>>
>>> Research has shown conflicting advice wrt the necessary headers, the
>>> order of the headers, the presence or absence of the web page HTML, the
>>> PHP functions required to send the file, etc.
>>
>> Here's what I do to send a file:
>>
>> <?php
>>
>> $file = '/path/to/somefile.zip';
>>
>> header('Content-Description: File Transfer');
>> header('Content-Type: application/octet-stream');
>> header('Content-Disposition: attachment; filename=' . basename($file));
>> header('Content-Transfer-Encoding: binary');
>> header('Expires: 0');
>> header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
>> header('Pragma: public');
>> header('Content-Length: ' . filesize ($file));
>>
>> ob_clean ();
>> flush ();
>> readfile ($file);
>>
>> ?>
>>
>> and this works for me. The file containing this PHP is the action of a
>> <form> which is submitted when the user clicks a button.
>>
>
> Thanks, Tim, but this doesn't work for me, and seems to have problems in
> general.
>
> Instead of getting a refreshed web page (containing new content, as per
> the PHP processing of the $_POST data) /and/ a (in this case PNG) file
> downloading, I get a display of the PNG file (as if it had been imbedded
> in it's own webpage) and nothing else.

Here's the PHP I used for this test:

<?php
function SendTheFile()
{
$file="./SixSpot_d.png";
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize ($file));
readfile($file);
}

session_start();
switch ($_SERVER['REQUEST_METHOD'])
{
case 'GET':
$count = 0;
break;

case 'POST':
$count = $_SESSION['Count'];
if (isset($_POST['Action']) && $_POST['Action'] == 'Send')
SendTheFile();
$count = $count + 1;
break;
}

?>
<html>
<head><title>Trial Sendfile</title></head>
<body>
<h1><?php print $count ?></h1>
<p>Did you get it?</p>
<form method="post">
<input type="submit" name="Action" value="Send"/>
</form>
</body>
</html>
<?php
$_SESSION['Count'] = $count;
?>

Note that the named file ("./SixSpot_d.png") is a PNG graphic, residing in
the same directory as this PHP page. I chose this file arbitrarily; if the
PHP does what I want, I should see
a) On initial entry, the web page displays a header of "O" and the Send
button
b) When the "Send" button is selected, the web page should refresh to
show "1" as the page header (rather than "0"), and I should receive
the SixSpot_d.png in my download directory.

What I actually see is
a) On initial entry, the web page displays a header of "O" and the Send
button
b) When the "Send" button is selected, the browser does download the
selected file, but does not refresh the webpage.

--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request
Re: Generating "download" pages [message #186411 is a reply to message #186408] Sat, 19 July 2014 18:23 Go to previous messageGo to next message
Lew Pitcher is currently offline  Lew Pitcher
Messages: 60
Registered: April 2013
Karma: 0
Member
On Saturday 19 July 2014 13:43, in comp.lang.php, "Christoph M. Becker"
<cmbecker69(at)arcor(dot)de> wrote:

> Thomas 'PointedEars' Lahn 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.
>>>
>>> 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
>
> How is that supposed to work? HTTP can only deliver a single response,
> and AFAIK there is no such thing as multipart responses for HTTP.

That's what I suspected.

So, given that I'd like two things to happen (the web page to refresh /and/
a file to download) on one HTTP request (ideally, a POST), what sort of
processing do I need to do in PHP? Or, /can/ I do this at all? Obviously,
some web pages /do/ this sort of thing, so it must be possible, but /how/
they do it is the question I can't answer.

--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request
Re: Generating "download" pages [message #186412 is a reply to message #186408] Sat, 19 July 2014 18:50 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
Christoph M. Becker wrote:

> Thomas 'PointedEars' Lahn 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.
>>>
>>> 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
>
> How is that supposed to work? HTTP can only deliver a single response,

There *is* only a single response delivered at the same time.

> and AFAIK there is no such thing as multipart responses for HTTP.

There is; that is the purpose of the “Content-Disposition” header field.

<http://tools.ietf.org/html/rfc6266>

> Anyway, I have tried that idea, and that confirmed my presumption that
> the browser is redirected to the Location URI, but the "displayed
> content" is not shown.

Apparently it depends on how and to where you redirect. Most certainly
those two header fields are not sufficient, but then again I never claimed
they were. I fact, I had said how I arrived at my suggestion, and referred
the OP to additional documentation (which apparently nobody bothered to
read).

AISB, I have found this on sourceforge.net. I went to

< http://sourceforge.net/projects/viplugin/files/viplugin/0.2.11/viPlugin_0.2 .11_E30.zip/download?use_mirror=sunet&r=&use_mirror=sunet>

and canceled the download dialog that appeared. Then I clicked on the link
with caption “direct link”. According to Chrome Dev Tools, this issues the
following HTTP request:

,----
| Remote Address:216.34.181.59:80
| Request
URL:http://downloads.sourceforge.net/project/viplugin/viplugin/0.2.11/viPlu gin_0.2.11_E30.zip?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fviplugin%2Ff iles%2Flatest%2Fdownload&ts=1405792642&use_mirror=netcologne
| Request Method:GET
| Status Code:302 Found
|
| Request Headers (source)
|
| GET
/project/viplugin/viplugin/0.2.11/viPlugin_0.2.11_E30.zip?r=http%3A%2F%2Fso urceforge.net%2Fprojects%2Fviplugin%2Ffiles%2Flatest%2Fdownload&ts=1405 792642&use_mirror=netcologne
HTTP/1.1
| Host: downloads.sourceforge.net
| Connection: keep-alive
| Cache-Control: no-cache
| Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
| Pragma: no-cache
| User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/34.0.1847.137 Safari/537.36
| Referer:
http://sourceforge.net/projects/viplugin/files/viplugin/0.2.11/viPlugin_0.2 .11_E30.zip/download?use_mirror=sunet&r=&use_mirror=sunet
| Accept-Encoding: gzip,deflate,sdch
| Accept-Language: de-CH,de;q=0.8,en-US;q=0.6,en;q=0.4
| Cookie: __utma=191645736.1110356561.1304966085.1405697254.1405792585.104;
__utmb=191645736.6.9.1405792650797; __utmc=191645736;
__utmz=191645736.1405344204.102.90.utmcsr=tvbrowser.org|utmccn=(referral)|
utmcmd=referral|utmcct=/index.php; __utmv=191645736.|
5=AB%20Test=4091748957%3A=1; sf_mirror_attempt=viplugin:sunet|
netcologne:/viplugin/viplugin/0.2.11/viPlugin_0.2.11_E30.zip
|
| Response Headers (source)
|
| HTTP/1.1 302 Found
| Content-Type: text/html
| Content-Length: 0
| Content-Disposition: attachment; filename="viPlugin_0.2.11_E30.zip"
| Date: Sat, 19 Jul 2014 17:58:15 GMT
| Location:
http://netcologne.dl.sourceforge.net/project/viplugin/viplugin/0.2.11/viPlu gin_0.2.11_E30.zip
| Server: lighttpd
| Set-Cookie: sf_mirror_attempt=viplugin:sunet|netcologne|
netcologne:/viplugin/viplugin/0.2.11/viPlugin_0.2.11_E30.zip; expires=Sat,
19-Jul-2014 18:00:15 GMT; Path=/
| X-Frame-Options: SAMEORIGIN
`----

Note that the response body is displayed as empty.

But for the next request, triggered by that response:

,----
| Remote Address:78.35.24.46:80
| Request
URL:http://netcologne.dl.sourceforge.net/project/viplugin/viplugin/0.2.11/v iPlugin_0.2.11_E30.zip
| Request Method:GET
| Status Code:200 OK
|
| Request Headers (source)
|
| GET /project/viplugin/viplugin/0.2.11/viPlugin_0.2.11_E30.zip HTTP/1.1
| Host: netcologne.dl.sourceforge.net
| Connection: keep-alive
| Cache-Control: no-cache
| Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
| Pragma: no-cache
| User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/34.0.1847.137 Safari/537.36
| Referer:
http://sourceforge.net/projects/viplugin/files/viplugin/0.2.11/viPlugin_0.2 .11_E30.zip/download?use_mirror=sunet&r=&use_mirror=sunet
| Accept-Encoding: gzip,deflate,sdch
| Accept-Language: de-CH,de;q=0.8,en-US;q=0.6,en;q=0.4
| Cookie: __utma=191645736.1110356561.1304966085.1405697254.1405792585.104;
__utmb=191645736.6.9.1405792650797; __utmc=191645736;
__utmz=191645736.1405344204.102.90.utmcsr=tvbrowser.org|utmccn=(referral)|
utmcmd=referral|utmcct=/index.php; __utmv=191645736.|
5=AB%20Test=4091748957%3A=1
|
| Response Headers (source)
|
| HTTP/1.1 200 OK
| Content-Type: application/octet-stream
| Content-Length: 161071
| Connection: close
| Accept-Ranges: bytes
| Date: Sat, 19 Jul 2014 17:58:15 GMT
| ETag: "181f60-2752f-3d7fa7c386b00"
| Last-Modified: Tue, 13 Apr 2004 22:35:56 GMT
| Server: Apache/2.2.22 (Debian)
`----

I do not understand yet why the “Content-Disposition” header field was used;
maybe it has to do with the fact that the HTTP "connection" was not closed.

I think the relevant fact here is that the target resource is served with
“Content-Type: application/octet-stream”, because that is known to trigger a
download dialog instead of navigation. (It would not work, for example,
with PNG resources by default, because those are served with “Content-Type:
image/png” by default and the browser would be able to display the resource,
which it does after self-navigation.)

[Note that I must and can strongly recommend the Vrapper plugin, to be found
on the Eclipse Marketplace and compatible with Eclipse 4.4.0 at least, over
the viPlugin developed for Eclipse 3.0. I just had this URI in my history
from months, if not years, ago.]

> Using a Refresh header instead of Location might work, but on one hand
> the Refresh is not part of the HTTP/1.1 specification (CMIIW),

Yes, it has only been claimed, but not substantiated, to be a quasi-standard
introduced by Netscape, that is supported by “just about every browser”.

<http://stackoverflow.com/questions/283752/refresh-http-header>

> and on the other the effect is not exactly what the OP asked for.

I think it would, given the appropriate header.


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
Re: Generating "download" pages [message #186413 is a reply to message #186412] Sat, 19 July 2014 20:06 Go to previous messageGo to next message
Christoph Michael Bec is currently offline  Christoph Michael Bec
Messages: 207
Registered: June 2013
Karma: 0
Senior Member
Thomas 'PointedEars' Lahn wrote:

> Christoph M. Becker wrote:
>
>> and AFAIK there is no such thing as multipart responses for HTTP.
>
> There is; that is the purpose of the “Content-Disposition” header field.
>
> <http://tools.ietf.org/html/rfc6266>

Um, I am somewhat confused. RFC 6266 says (emphasis mine):

| The Content-Disposition response header field is used to convey
| additional information about *how to process the response payload*,
| and also can be used to attach additional metadata, such as the
| filename to use when *saving the response payload locally*.

This seems to be completely different then e.g. "Content-Type:
multipart/alternative" for emails.

> | Response Headers (source)
> |
> | HTTP/1.1 302 Found
> | Location:
> http://netcologne.dl.sourceforge.net/project/viplugin/viplugin/0.2.11/viPlu gin_0.2.11_E30.zip
>
> Note that the response body is displayed as empty.

This is not surprising, as the HTTP response status code is "302 Found",
which redirects to the URI given in the Location header field.

> I think the relevant fact here is that the target resource is served with
> “Content-Type: application/octet-stream”, because that is known to trigger a
> download dialog instead of navigation.

ACK. However, the content that could be saved, is the payload of the
very response that contained the Content-Type header field.

> <http://stackoverflow.com/questions/283752/refresh-http-header>

Thanks for the confirmation.

[Sorry, I had to snip more of the former discussion than I liked,
because my newsserver doesn't allow too much quoted content.]

--
Christoph M. Becker
Re: Generating "download" pages [message #186414 is a reply to message #186411] Sat, 19 July 2014 20:18 Go to previous messageGo to next message
Christoph Michael Bec is currently offline  Christoph Michael Bec
Messages: 207
Registered: June 2013
Karma: 0
Senior Member
Lew Pitcher wrote:

So, given that I'd like two things to happen (the web page to refresh /and/
> a file to download) on one HTTP request (ideally, a POST), what sort of
> processing do I need to do in PHP?

As Thomas had already pointed out (no pun intended), this has nothing to
do with PHP in a strict sense, but is an HTTP issue.

> Or, /can/ I do this at all?

I still don't think that it is possible via HTTP only.

> Obviously,
> some web pages /do/ this sort of thing, so it must be possible, but /how/
> they do it is the question I can't answer.

Please post an URL to such a ressource. Maybe others can answer how
they are doing it.

One solution relying on client side ECMAScript support would be to add
the following script element to the document (e.g. at the bottom of the
body element):

<script>window.location = "file-to-download.ext"</script>

--
Christoph M. Becker
Re: Generating "download" pages [message #186415 is a reply to message #186414] Sat, 19 July 2014 20:38 Go to previous messageGo to next message
Christoph Michael Bec is currently offline  Christoph Michael Bec
Messages: 207
Registered: June 2013
Karma: 0
Senior Member
Christoph M. Becker wrote:

> One solution relying on client side ECMAScript support would be to add
> the following script element to the document (e.g. at the bottom of the
> body element):
>
> <script>window.location = "file-to-download.ext"</script>

Of course the download resource has to be served with a Content-Type
header field that forces the client to treat it as download.

--
Christoph M. Becker
Re: Generating "download" pages [message #186416 is a reply to message #186415] Sat, 19 July 2014 20:54 Go to previous messageGo to next message
Lew Pitcher is currently offline  Lew Pitcher
Messages: 60
Registered: April 2013
Karma: 0
Member
On Saturday 19 July 2014 16:38, in comp.lang.php, "Christoph M. Becker"
<cmbecker69(at)arcor(dot)de> wrote:

> Christoph M. Becker wrote:
>
>> One solution relying on client side ECMAScript support would be to add
>> the following script element to the document (e.g. at the bottom of the
>> body element):
>>
>> <script>window.location = "file-to-download.ext"</script>
>
> Of course the download resource has to be served with a Content-Type
> header field that forces the client to treat it as download.
>

Well, I'm not yet familiar enough with ECMAScript/JavaScript to write this
sort of facility into my web pages.

However, I have found a workaround that will suffice until I determine the
proper way to get both updated page /and/ download:

The request page (that which I want to update and redisplay) will contain
within it an (almost) invisible <iframe> linking to a /second/ page. That
second page will /only/ generate the file transfer headers and file.

Together, the two pages will do what I had hoped to do in one page.

Thanks to all for all the advice.
--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request
Re: Generating "download" pages [message #186417 is a reply to message #186413] Sat, 19 July 2014 20:54 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 7/19/2014 4:06 PM, Christoph M. Becker wrote:
> Thomas 'PointedEars' Lahn wrote:
>
>> Christoph M. Becker wrote:
>>
>>> and AFAIK there is no such thing as multipart responses for HTTP.
>>
>> There is; that is the purpose of the “Content-Disposition” header field.
>>
>> <http://tools.ietf.org/html/rfc6266>
>
> Um, I am somewhat confused. RFC 6266 says (emphasis mine):
>
> | The Content-Disposition response header field is used to convey
> | additional information about *how to process the response payload*,
> | and also can be used to attach additional metadata, such as the
> | filename to use when *saving the response payload locally*.
>
> This seems to be completely different then e.g. "Content-Type:
> multipart/alternative" for emails.
>
>> | Response Headers (source)
>> |
>> | HTTP/1.1 302 Found
>> | Location:
>> http://netcologne.dl.sourceforge.net/project/viplugin/viplugin/0.2.11/viPlu gin_0.2.11_E30.zip
>>
>> Note that the response body is displayed as empty.
>
> This is not surprising, as the HTTP response status code is "302 Found",
> which redirects to the URI given in the Location header field.
>
>> I think the relevant fact here is that the target resource is served with
>> “Content-Type: application/octet-stream”, because that is known to trigger a
>> download dialog instead of navigation.
>
> ACK. However, the content that could be saved, is the payload of the
> very response that contained the Content-Type header field.
>
>> <http://stackoverflow.com/questions/283752/refresh-http-header>
>
> Thanks for the confirmation.
>
> [Sorry, I had to snip more of the former discussion than I liked,
> because my newsserver doesn't all ow too much quoted content.]
>

Christopher,

Don't worry, Pointed Head is just showing his ignorance again. You are
correct - you can't send two different URLs as a response to a single
request.

The easiest way to do it, IMHO, is to just put a javascript request in
the onload event (of the <body> tag). Have that perform the download.

Arno's idea is interesting, also. I admit I haven't tried it, but it
would be worth looking at when I get a few minutes, probably next week.

--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
Re: Generating "download" pages [message #186418 is a reply to message #186404] Sat, 19 July 2014 20:55 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 7/19/2014 12:17 PM, Arno Welzel wrote:
> Lew Pitcher, 2014-07-18 15:55:
>
>> I'm not certain that what I want can be done, let alone done with PHP, but
>> please let me describe the function I'm looking for:
>>
>>
>> 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? How do I do this with PHP?
>
> I would solve it this way:
>
> A PHP script displays the page *and* also generates a
> META-Refresh-Header to redirect the browser to another script (or the
> same whith an additional parameter) which will then generate the content
> to be downloaded.
>
> As a rough example (untested and not complete - just to get the idea):
>
> <?php
> //
> // getfile.php
> //
>
> if(!isset($_GET['download'))
> {
> ?>
> <!DOCTYPE html>
> <html>
> <head>
> <meta
> http-equiv="refresh"
> content="5; url=http://example.com/getfile.php?download=1" />
> <title>Download</title>
> </head>
> <body>
> <p>If your download does not start automatically,
> <a href="http://example.com/getfile.php?download=1">click here</a>.</p>
> </body>
> </html>
> <?
> }
> else
> {
> header("Content-Disposition: attachment; filename=download.xml");
>
> // Add XML output to be downloaded here...
> }
> ?>
>
>

Arno,

An interesting idea. I admit I hadn't thought of using a meta refresh
that way; it's worth a look. The couple of times I've needed to do
something like this I've used javascript.

--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
Re: Generating "download" pages [message #186419 is a reply to message #186402] Sat, 19 July 2014 20:57 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 7/19/2014 11:38 AM, Lew Pitcher wrote:
> Thanks for the response, Thomas.
>
> Next time, please contain your snark. It ill suits you.
>
> On Friday 18 July 2014 11:39, in comp.lang.php, "Thomas 'PointedEars' Lahn"
> <PointedEars(at)web(dot)de> wrote:
>
>> 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)
>
> I can, by viewing the source of web pages that use multiple javascript files
> with intentionally convoluted logic, and filtering out (in a masterly way)
> all that extraneous stuff, find that the web page in question (such as the
> download page for a sourceforge project) does *not* include the "server
> side" logic that does this. I can /then/ examine the headers from such a
> working page, *deduce* that the page sent both html
> and "Content-Disposition" (etc.) headers, and *assume* the method of
> generating such.
>
> Indeed, this is how I've done it in the past, with poor results.
>
>
>>> How do I do this with PHP?
>>
>> There are several ways. Another is:
>
> And, the first was?
>
>>
>> <?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.
>
> But, to set headers, you need some sort of active language. Mine is PHP.
>
>> You can use browser developer tools to inspect the HTTP
>> response headers, then use the corresponding PHP functions to achieve the
>> same.
>
> Or, I can ask in a forum that specializes in such programming, and save
> myself the blind alleys, false starts, and mis-assumptions that such an
> inspection of the outside effects would bring
>
> [snip suggested tools]
>
>
>>
>> Next time, do your homework, please.
>
> Condescending, no?
>
> In fact, I've done my homework. And *this* is part of that homework.
>
> Thomas, either be helpful or don't reply. Such snark is not helpful.
>

Lew,

Don't worry - Pointed Head is just being his usual pedantic self. And
he's once again showing his ignorance, since you can't provide two
responses to one HTTP request (and can't send two different content
types for a single request).

For more info, please see my other updates.

--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
Re: Generating "download" pages [message #186420 is a reply to message #186416] Sat, 19 July 2014 21:00 Go to previous messageGo to next message
Lew Pitcher is currently offline  Lew Pitcher
Messages: 60
Registered: April 2013
Karma: 0
Member
On Saturday 19 July 2014 16:54, in comp.lang.php, "Lew Pitcher"
<lew(dot)pitcher(at)digitalfreehold(dot)ca> wrote:

[snip]

> However, I have found a workaround that will suffice until I determine the
> proper way to get both updated page /and/ download:
>
> The request page (that which I want to update and redisplay) will contain
> within it an (almost) invisible <iframe> linking to a /second/ page. That
> second page will /only/ generate the file transfer headers and file.
>
> Together, the two pages will do what I had hoped to do in one page.
>
> Thanks to all for all the advice.

The main page (sendfile_2.php) looks like this....

<?php
session_start();
$showfile = false;

switch ($_SERVER['REQUEST_METHOD'])
{
case 'GET':
$count = 0;
break;

case 'POST':
$count = 1 + $_SESSION['Count'];
$showfile = (isset($_POST['Action']) && $_POST['Action'] == 'Send');
break;
}
?>
<html>
<head><title>Trial Sendfile</title></head>
<body>
<h1><?php print $count ?></h1>
<p>Did you get it?</p>
<form method="post">
<input type="submit" name="Action" value="Send"/>
</form>
<?php
if ($showfile)
{
?><iframe src="sendfile_2a.php" width="0" height="0" border="0"
frameborder="0" /><?php
}
?>
</body>
</html>
<?php
$_SESSION['Count'] = $count;
?>


The "download helper" page (referenced in the iframe and
called "sendfile_2a.php here) looks like this...

<?php
$file="./SixSpot_d.png";

header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($file));
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize ($file));
readfile($file);
exit(0);
?>


--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request
Re: Generating "download" pages [message #186421 is a reply to message #186419] Sat, 19 July 2014 21:06 Go to previous messageGo to next message
Lew Pitcher is currently offline  Lew Pitcher
Messages: 60
Registered: April 2013
Karma: 0
Member
On Saturday 19 July 2014 16:57, in comp.lang.php, "Jerry Stuckle"
<jstucklex(at)attglobal(dot)net> wrote:

> On 7/19/2014 11:38 AM, Lew Pitcher wrote:
>> Thanks for the response, Thomas.
>>
>> Next time, please contain your snark. It ill suits you.
>>
>> On Friday 18 July 2014 11:39, in comp.lang.php, "Thomas 'PointedEars'
>> Lahn" <PointedEars(at)web(dot)de> wrote:
[snip]
>
> Lew,
>
> Don't worry - Pointed Head is just being his usual pedantic self.

I'm not worried about Thomas. He's free to express his advice and opinions -
and now, having heard and evaluated both, I'm free to ignore him.

> And
> he's once again showing his ignorance, since you can't provide two
> responses to one HTTP request (and can't send two different content
> types for a single request).

This truth has escaped me. Obviously, there are Jedi Master ways to code
pages so that they /appear/ to provide two (or more) responses to one HTTP
request. I just thought that those ways were readily known with PHP
examples.


> For more info, please see my other updates.

Thanks, I have.

And, you might be interested in the workaround that /I/ concocted, once I
realized the truth about HTTP responses. See Message-ID:
<d0Byv.32651$46(dot)29400(at)fx19(dot)iad> for a working PHP/HTML example that does
what I wanted my page to do. Others might find it helpful, as well

Thanks again
--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request
Re: Generating "download" pages [message #186422 is a reply to message #186408] Sat, 19 July 2014 23:04 Go to previous messageGo to next message
Arno Welzel is currently offline  Arno Welzel
Messages: 317
Registered: October 2011
Karma: 0
Senior Member
Christoph M. Becker, 2014-07-19 19:43:

> Thomas 'PointedEars' Lahn 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.
>>>
>>> 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
>
> How is that supposed to work? HTTP can only deliver a single response,
> and AFAIK there is no such thing as multipart responses for HTTP.

It will not work - the browser will likely follow the Location header
and just ignore the Content-Disposition.

> Using a Refresh header instead of Location might work, but on one hand
> the Refresh is not part of the HTTP/1.1 specification (CMIIW), and on
> the other the effect is not exactly what the OP asked for. It seems to
> me the only way to get this behavior would be in combination with client
> side scripting, what would be on-topic for comp.lang.javascript, for
> instance.

Yep - it's right, a Refresh header is not part of HTTP/1.1 - but most
browsers will still accept it (at least when using <meta
http-equiv="refresh" ...>) and behave as expected. As a fall back one
should offer a direct link within the displayed content anyway - since
client side scripting may also not work if the user did not enable it.



--
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
http://fahrradzukunft.de
Re: Generating "download" pages [message #186424 is a reply to message #186409] Wed, 23 July 2014 00:38 Go to previous message
Curtis Dyer is currently offline  Curtis Dyer
Messages: 34
Registered: January 2011
Karma: 0
Member
Lew Pitcher wrote:

> On Saturday 19 July 2014 12:36, in comp.lang.php, "Tim Streater"
> <timstreater(at)greenbee(dot)net> wrote:
>
>> In article <b_wyv.50770$OC3(dot)15102(at)fx18(dot)iad>, Lew Pitcher
>> <lew(dot)pitcher(at)digitalfreehold(dot)ca> wrote:

<snip>

>> Here's what I do to send a file:
>>
>> <?php
>>
>> $file = '/path/to/somefile.zip';
>>
>> header('Content-Description: File Transfer');
>> header('Content-Type: application/octet-stream');
>> header('Content-Disposition: attachment; filename=' .
>> basename($file)); header('Content-Transfer-Encoding: binary');
>> header('Expires: 0');
>> header('Cache-Control: must-revalidate, post-check=0,
>> pre-check=0'); header('Pragma: public');
>> header('Content-Length: ' . filesize ($file));
>>
>> ob_clean ();
>> flush ();
>> readfile ($file);
>>
>> ?>
>>
>> and this works for me. The file containing this PHP is the
>> action of a <form> which is submitted when the user clicks a
>> button.
>
> Thanks, Tim, but this doesn't work for me, and seems to have
> problems in general.

I think you can make this much easier on yourself if you separate
the PHP code that generates the downloadable content into its own
file, and then have another resource that includes the HTML markup
and/or scripting that requests the download.

> Instead of getting a refreshed web page (containing new content,
> as per the PHP processing of the $_POST data) /and/ a (in this
> case PNG) file downloading, I get a display of the PNG file (as
> if it had been imbedded in it's own webpage) and nothing else.

Try something like the following model:

Make a PHP script that simply generates the downloadable content.
A very simple version might look like:

<?php
/* download.php */

define('FILENAME', 'img-name.png');

function outputfile($file = '')
{
$disposition = 'Content-Disposition: attachment';
if ($file)
$disposition .= "; filename=\"$file\"";

header('Content-Type: application/octet-stream');
header($disposition);

readfile(FILENAME);
}

/* output */
outputfile('foo.png');
?>


In a separate file, the "updated" page you want to display will
make the request for the download. You might also use the meta
refresh technique instead of client-side scripting.

<?php
/* update_page.php */

/*
* stuff ...
*/
?><!DOCTYPE html>
<html lang="en">
<head><title>Hello, world</title></head>
<body>

<h1>Users will see this</h1>

<p>
If they don't get the prompt, the user can
<a href="download.php">click here</a>.
</p>

<script>
window.location = "http://example.com/download.php";
</script>
</body>
</html>


With regard to putting these files to use, you might have
"update_page.php" the target of a form action, or something to
that effect (as Tim Streater provided). From there, you could pass
on any data to "download.php" itself in order to dynamically
generate the needed content.

<snip>

--
Curtis Dyer
<?$x='<?$x=%c%s%c;printf($x,39,$x,39);?>';printf($x,39,$x,39);?>
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Resolved: Generating "download" pages
Next Topic: Your opinion on which technologies to use when building web applications
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 22:08:35 GMT 2024

Total time taken to generate the page: 0.02473 seconds