Page MenuHomeDevCentral

D1111.diff
No OneTemporary

D1111.diff

diff --git a/dl.php b/dl.php
--- a/dl.php
+++ b/dl.php
@@ -13,14 +13,67 @@
*
*/
-$filename = isset($_REQUEST['filename']) ? $_REQUEST['filename'] : '';
-$contentType = isset($_REQUEST['contentType']) ? $_REQUEST['contentType'] : 'text/plain';
+class DownloadEntryPoint {
-header('Content-Type: ' . $contentType);
-if ($filename !== '') {
- header("Content-Disposition: attachment; filename=\"$filename\"");
+ private $request;
+
+ function __construct ($request = null) {
+ $this->storeRequest($request);
+ }
+
+ function run () {
+ $this->sendHeaders();
+ $this->sendBody();
+ }
+
+ ///
+ /// Task methods
+ ///
+
+ private function storeRequest ($request) {
+ if ($request === null) {
+ $this->request = $_REQUEST;
+ } else {
+ $this->request = $request;
+ }
+ }
+
+ function sendHeaders() {
+ $contentType = $this->getFromRequest('content-type', 'text/plain');
+ header('Content-Type: ' . $contentType);
+
+ $this->sendContentDispositionHeader();
+ header('Pragma: no-cache');
+ header('Expires: 0');
+ }
+
+ private function sendBody () {
+ echo $this->getFromRequest('result');
+ }
+
+ ///
+ /// Helper methods
+ ///
+
+ private function getFromRequest($parameter, $defaultValue = '') {
+ if (isset($_REQUEST[$parameter])) {
+ return $_REQUEST[$parameter];
+ }
+
+ return $defaultValue;
+ }
+
+ private function sendContentDispositionHeader () {
+ $filename = $this->getFromRequest('filename');
+
+ if ($filename !== '') {
+ header(
+ 'Content-Disposition: attachment; filename="'
+ . $filename . '"'
+ );
+ }
+ }
}
-header('Pragma: no-cache');
-header('Expires: 0');
-echo $_REQUEST['result'];
+$app = new DownloadEntryPoint;
+$app->run();

File Metadata

Mime Type
text/plain
Expires
Thu, May 1, 04:07 (17 h, 41 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2620505
Default Alt Text
D1111.diff (1 KB)

Event Timeline