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 #186404 is a reply to message #186399] Sat, 19 July 2014 16:17 Go to previous messageGo to previous message
Arno Welzel is currently offline  Arno Welzel
Messages: 317
Registered: October 2011
Karma:
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
[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: Sun Dec 22 02:32:44 GMT 2024

Total time taken to generate the page: 0.05112 seconds