Skip to content

Commit 0fd1e2b

Browse files
committed
Don't use echo; but a Response object
1 parent 4a901bd commit 0fd1e2b

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

controller/main.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
namespace phpbbde\pastebin\controller;
1212

13+
use Symfony\Component\HttpFoundation\Response;
14+
1315
class main
1416
{
1517
const CONFIRM_PASTEBIN = 5;
@@ -112,7 +114,10 @@ public function handle($name = '')
112114
'U_VIEW_FORUM' => $this->helper->route('phpbbde_pastebin_main_controller'),
113115
));
114116

115-
$this->display_pb();
117+
if ($response = $this->display_pb())
118+
{
119+
return $response;
120+
}
116121

117122
return $this->helper->render('pastebin_body.html', $this->user->lang['PASTEBIN']);
118123
}
@@ -429,23 +434,20 @@ private function display_pb()
429434
$filename = "filename*=UTF-8''" . rawurlencode($filename);
430435
}
431436

432-
header('Pragma: public');
433-
434-
// Send out the Headers. Do not set Content-Disposition to inline please, it is a security measure for users using the Internet Explorer.
435-
header('Content-Type: text/plain');
436-
header("Content-Disposition: attachment; $filename");
437+
// Do not set Content-Disposition to inline please, it is a security measure for users using the Internet Explorer.
438+
$response = new Response($snippet_text, Response::HTTP_OK);
439+
$response->headers->set('Pragma', 'public');
440+
$response->headers->set('Content-Type', 'text/plain');
441+
$response->headers->set('Content-Disposition', "attachment; $filename");
437442

438443
if ($size = @strlen($snippet_text))
439444
{
440-
header("Content-Length: $size");
445+
$response->headers->set('Content-Length', $size);
441446
}
442447

443448
@set_time_limit(0);
444449

445-
echo $snippet_text;
446-
447-
flush();
448-
exit;
450+
return $response;
449451
}
450452
else if ($mode == 'moderate')
451453
{

0 commit comments

Comments
 (0)