/** * Constructor. * * @access public * @param string $file File path * @param array $options Options */ public function __construct($file, array $options = array()) { if (!file_exists($file) || !is_readable($file)) { throw new RuntimeException(vsprintf('File %s is not readeable or not exist', array($file))); } $this->filePath = $file; $this->options = $options + array('fileName' => basename($file), 'disposition' => 'attachment', 'contentType' => Mime::get($file)); }
/** * Handle the response * * @param \Opis\Http\Request $request Http request * @param \Opis\Http\Response $response Http response */ public function handle(Request $request, Response $response) { $response->contentType(Mime::get($this->filePath)); $file = $this->filePath; $response->body(function ($request, $response) use($file) { readfile($file); }); $response->send(); }