Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #14123

Re: Generating "download" pages

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.php
Subject Re: Generating "download" pages
Date 2014-07-19 20:50 +0200
Organization PointedEars Software (PES)
Message-ID <1978758.sLNZCN5jEe@PointedEars.de> (permalink)
References <6H9yv.30802$el1.16727@fx26.iad> <6732922.VsfUzaneRC@PointedEars.de> <lqeamt$jjv$1@solani.org>

Show all headers | View raw


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/viPlugin_0.2.11_E30.zip?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fviplugin%2Ffiles%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%2Fsourceforge.net%2Fprojects%2Fviplugin%2Ffiles%2Flatest%2Fdownload&ts=1405792642&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/viPlugin_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/viPlugin_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

Back to comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Generating "download" pages Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2014-07-18 09:55 -0400
  Re: Generating "download" pages Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-07-18 17:39 +0200
    Re: Generating "download" pages Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2014-07-19 11:38 -0400
      Re: Generating "download" pages Jerry Stuckle <jstucklex@attglobal.net> - 2014-07-19 16:57 -0400
        Re: Generating "download" pages Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2014-07-19 17:06 -0400
    Re: Generating "download" pages Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2014-07-19 11:58 -0400
      Re: Generating "download" pages Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-07-19 19:06 +0200
    Re: Generating "download" pages "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-07-19 19:43 +0200
      Re: Generating "download" pages Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2014-07-19 14:23 -0400
        Re: Generating "download" pages "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-07-19 22:18 +0200
          Re: Generating "download" pages "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-07-19 22:38 +0200
            Re: Generating "download" pages Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2014-07-19 16:54 -0400
              Re: Generating "download" pages Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2014-07-19 17:00 -0400
                Resolved: Generating "download" pages Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2014-07-20 14:34 -0400
      Re: Generating "download" pages Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-07-19 20:50 +0200
        Re: Generating "download" pages "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-07-19 22:06 +0200
          Re: Generating "download" pages Jerry Stuckle <jstucklex@attglobal.net> - 2014-07-19 16:54 -0400
          Re: Generating "download" pages Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-07-20 00:48 +0200
      Re: Generating "download" pages Arno Welzel <usenet@arnowelzel.de> - 2014-07-20 01:04 +0200
  Re: Generating "download" pages Arno Welzel <usenet@arnowelzel.de> - 2014-07-19 18:17 +0200
    Re: Generating "download" pages Jerry Stuckle <jstucklex@attglobal.net> - 2014-07-19 16:55 -0400
  Re: Generating "download" pages Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2014-07-19 12:25 -0400
    Re: Generating "download" pages Tim Streater <timstreater@greenbee.net> - 2014-07-19 17:36 +0100
      Re: Generating "download" pages Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2014-07-19 13:53 -0400
        Re: Generating "download" pages Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2014-07-19 14:14 -0400
        Re: Generating "download" pages Curtis Dyer <dyer85@gmail.com> - 2014-07-23 00:38 +0000

csiph-web