function render($output_body=true)
{
- if ($this->status_code >= 200
- && $this->status_code != 204
- && $this->status_code != 304) {
+ if ($this->status_code >= 200
+ && $this->status_code != 204
+ && $this->status_code != 304
+ && !ArrayTools::get($this->headers, 'Content-Length')) {
+
$this->headers['Content-Length'] = strlen($this->content);
}
+
$this->outputHeaders();
- if ($output_body) {
- echo($this->content);
- }
+ if ($output_body)
+ $this->outputBody();
}
function outputHeaders()
}
}
}
+
+ function outputBody()
+ {
+ echo $this->content;
+ }
}
+
--- /dev/null
+<?php
+
+class IPF_HTTP_Response_File extends IPF_HTTP_Response
+{
+ private $filename;
+
+ function __construct($filename, $downloadName, $mimetype='application/octet-stream')
+ {
+ parent::__construct('', $mimetype);
+ $this->filename = $filename;
+ $this->headers['Content-Description'] = 'File Transfer';
+ $this->headers['Content-Disposition'] = 'attachment; filename='.basename($downloadName);
+ $this->headers['Content-Transfer-Encoding'] = 'binary';
+ $this->headers['Content-Length'] = filesize($filename);
+ }
+
+ function outputBody()
+ {
+ if (ob_get_level())
+ ob_end_clean();
+ readfile($this->filename);
+ }
+}
+