Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Resolved: Generating "download" pages
Show: Today's Messages :: Unread Messages :: Polls :: Message Navigator
| Subscribe to topic | Bookmark topic 
Switch to threaded view of this topic Create a new topic Submit Reply
Resolved: Generating "download" pages [message #186423] Sun, 20 July 2014 14:34
Lew Pitcher is currently offline  Lew Pitcher
Messages: 60
Registered: April 2013
Karma: 0
add to buddy list
ignore all messages by this user
For reference (corrected):

> On Saturday 19 July 2014 17:00, in comp.lang.php, "Lew Pitcher"
> <lew(dot)pitcher(at)digitalfreehold(dot)ca> wrote:
>> 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:

I've refined the technique a bit, and created a standalone PHP page.

For reference:
=================== Source code below =================================

function SendFile($file)
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));

$msg = null;

case 'GET':
if (isset($_GET['type']))
switch ($_GET['type'])
case 'HTML':

<html><body><p>Sorry, I don't know how to send you a
<?php print $_GET['type']; ?> file</p></body></html>

case 'POST':
switch ($_POST['Format'])
case 'HTML':
$msg = "Downloading ".$_SERVER['SCRIPT_FILENAME']." to you";
<head><title>Trial Sendfile</title></head>
<h1>Download Form</h1>
<form name="Download" method="post">
<dd><input type="radio" name="Format" value="HTML"/>webpage</dd>
<dd><input type="radio" name="Format" value="XYZ"/>unknown format</dd>
<dd><input type="submit"/></dd>
if (isset($msg))

** In order for the page to render properly, we need to ensure **
** that the <iframe> appears as the last element of the page **
** Otherwise, the render stops at the <iframe>, and does not **
** show any of the page that follows it. **
if ($_POST['Format'])
printf("<iframe src=\"%s?type=%s\" border=\"0\" frameborder=\"0\" />\n",
=================== Source code above =================================

This is a self-contained page:
GET with no (recognized) parameters will display the initial page
POST with required parameters will initiate download, and display
a modified page
GET with valid type= parameter will download the script
GET with invalid type= parameter will generate error HTML

On initial entry (GET with no parameters), a web form is presented to the
user. The user will select one of the two radio buttons, and click the
Submit button to initiate a POST.

On POST, the script will update the page html to include an appropriate
message (either "Downloading ..." or nothing) and emit the new page html.

The browser, will render the HTML, including the embedded <iframe>. The
<iframe> will initiate a secondary GET (with type= parameter) to the PHP,
which will determine the validity of the parameter. A valid parameter will
cause the PHP (on this secondary GET) to initiate a file download, while
an invalid parameter will cause the PHP to emit an error webpage, which
will display in the original POSTs <iframe>.

Thus, the /appearance/ of an updating webpage that simultaneously
downloads a file the the client system.

Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request
Quick Reply
Formatting Tools:   
  Switch to threaded view of this topic Create a new topic
Previous Topic: Encoding Problems
Next Topic: Generating "download" pages
Goto Forum:

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

Current Time: Wed Jun 12 22:05:07 EDT 2024

Total time taken to generate the page: 0.04913 seconds