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
Return to the default flat view Create a new topic Submit Reply
Re: Generating "download" pages [message #186412 is a reply to message #186408] Sat, 19 July 2014 18:50 Go to previous messageGo to previous message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma:
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
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
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: Sat Dec 21 15:55:38 GMT 2024

Total time taken to generate the page: 0.04516 seconds