protected function download($path, $display_if_can = true) { $pos = strrpos($path, '/'); $filename = substr($path, $pos + 1); if ($display_if_can && FileHelper::canShow($path)) { return Yii::$app->response->sendFile($path, $filename, ['inline' => true]); } return Yii::$app->response->sendFile($path, $filename); }
/** * Check if file can be displayed in browser * @return array */ public function canShow() { return FileHelper::canShow($this->getPath()); }