php文件下载

public function actionDo(){
        $id = (int)Yii::$app->request->get('id');
        if(empty($id)) {
            $this->_error('操作失败', 'index');
        }
        $service = new New2Service();
        $field = ['n.*','p.name as pName'];
        $data = $service->getOneNews(['n.id' => $id], $field);
        header('Content-type: application/pdf');
        header('Content-Disposition: attachment; filename="'.$data['pdf_name'].'"');
        echo file_get_contents(dirname(__DIR__).'/web'.$data['pdf_url']);
    }
原文地址:https://www.cnblogs.com/ghjbk/p/7767377.html