Reference - Output types - download


App: regression/output_download - Page: index
PHP
index.php
HTML
index.pad
Result
<?php

// The download writer's promise: the page arrives as a file attachment - a
// Content-Disposition naming a file, the body intact behind it.

$r = padCurl ( $padHost . 'regression/output_download/?payload&padInclude' );

$disposition = $r ['headers'] ['Content-Disposition'] ?? '';

$verdict = ( str_starts_with ( $r ['result'], '2' )
and
str_contains ( $disposition, 'attachment' )
and
str_contains ( $r ['data'], 'CARRIED ALL THE WAY' ) ) ? 'yes' : 'NO';

$output = 'download';

?>
<p>output type: {$output}</p>
<p>the payload arrived as this type promises: <b>{$verdict}</b></p>


App: regression/output_download - Page: late
PHP
late.php
HTML
late.pad
Result
<?php

// The fixture of lateread: a download that fails once it has gone out - a shutdown
// function warns, and another raises a PAD error.

register_shutdown_function ( function () { trigger_error ( 'warned after the download went out', E_USER_WARNING ); } );
register_shutdown_function ( function () { padError ( 'a PAD error after the download went out' ); } );

?>
the download


App: regression/output_download - Page: lateread
PHP
lateread.php
HTML
lateread.pad
Result
<?php

// A download ends where its Content-Length says: the writer sent the body and never said
// it had (padSent) nor turned PHP's display of errors off, as the web writer does, so an
// error after it - a shutdown function's warning, a late padError - was written behind
// the declared length. The download is read off the socket.

$url = parse_url ( $padHost . 'regression/output_download/?late&padInclude' );
$sock = fsockopen ( $url ['host'], $url ['port'] ?? 80, $errno, $errstr, 10 );

fwrite ( $sock, "GET {$url ['path']}?{$url ['query']} HTTP/1.1\r\nHost: {$url ['host']}\r\nConnection: close\r\n\r\n" );

[
$head, $body ] = explode ( "\r\n\r\n", stream_get_contents ( $sock ), 2 ) + [ '', '' ];

fclose ( $sock );

preg_match ( '/^Content-Length:\s*(\d+)/mi', $head, $length );

$lateEnds = ( isset ( $length [1] ) and strlen ( $body ) == $length [1] ) ? 'yes' : 'NO';

?>
<p>the download ends where its Content-Length says: {$lateEnds}</p>


App: regression/output_download - Page: payload
PHP
payload.php
HTML
payload.pad
Result
<?php

$greet
= 'carried all the way';

?>
<p>{$greet | upper}</p>