0
public function actionViewDownload(){

    // some in internal processing php commands (no echo)

    exec($command); // command to be executed compulsary

    $file = "/images/sample.jpg"; // some images file
    if (file_exists($file)) {
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename='.basename($file));
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate');
        header('Pragma: public');
        header('Content-Length: ' . filesize($file));
        readfile($file);
    }
    $this->render('view',array('data'=>$data)); // render the other view of the controller after/during download.

}

コマンドを実行してから画像ファイルをダウンロードし、ダウンロード後またはダウンロード中にビューをレンダリングする必要があります。
ダウンロードする前にビューをレンダリングすると、「ヘッダーは変更できません。ヘッダーは既に送信されています」というプロンプトが表示さ
れ、ダウンロード後にビューをレンダリングすると、ブラウザーにビューが表示されるようになりましたが、ファイルはダウンロードされます。ここでの私の質問は、コマンドの実行 (これが最初でなければなりません)、レンダリング、およびダウンロードの
3 つのタスクをどのように達成できるかということです。

4

1 に答える 1