Calling files(documents,pics) from another server

Hi guys,

following method will show each file in browser using external programs

    public function actionFile($filename, $id) {

        $session = new Session();

        $model_folder = Dateianhang::findOne(['id' => $id]);

        $folder_read = "/" . AppEinstellung::getSpeicherOrt($model_folder) . "/";

        $folder_base = Yii::getAlias('@app');

        $folder_read = $folder_base . $folder_read;

        if (!is_file("$folder_read/$filename")) {

            $model = Dateianhang::findOne(['id' => $id]);

            $id = EDateianhang::findOne(['id' => $model->id_e_dateianhang])->id_person;

            $session->addFlash("warning", "Die angeforderte Datei befindet sich nicht(mehr)auf Ihrem Server");

            return $this->redirect(['index', 'id' => $id]);


        //gib das Dokument im Browser aus

        return Yii::$app->response->sendFile("$folder_read/$filename");


What about doing same thing, if file is not in my local folder but at another webserver. Coding like this will show pictures without any problems.

    public function actionFile() {

        $url_moi = "";

        //gib das Dokument im Browser aus

        return Html::img($url_moi, ['alt' => 'pic not found']);


Coding like this will show documents in browser:

    public function actionFile($filename, $id) {

        $url = "";

        $url1 = "";

        $url2 = "";



[font="Arial"][size="2"]First url(Merksatz.docx) will be shown starting MSOffice, without influencing application in a special tab[/size][/font]

[font=“Arial”][size=“2”]That’s what I want!

[/size][size="2"]Second and third url will replace application in tab instead starting Adobe or another Editor[/size][/font]

[font=“Arial”][size=“2”]That’s, want i don’t want!

[/size][/font][color="#333333"][font="Arial"][size="2"]Is there a way to open all documents in a different/special tab?[/size][/font][/color]

As it’s not possible influencing HTTP-Header coding server side, I solved problem using code like this:

    public function actionFile() {

        $url1 = "";

        $url2 = "";

        $url3 = "";

        $GoBack = "/dateianhang/dateianhang/index";

        ?><?= "<div>" . Html::a('Show Word-Document', $url1, array('target' => '_blank')) . "</div>";

        ?><?= "<div>" . Html::a('Show PDF', $url2, array('target' => '_blank')) . "</div>";

        ?><?= "<div>" . Html::a('Show Text-File', $url3, array('target' => '_blank')) . "</div>";

        ?><?="<div>" . Html::a('Render Back', [$GoBack, 'id' => 8], ['title' => 'Kontaktdaten', 'data' => ['pjax' => '0']]) . "</div";


Nevertheless: if there is any possibilitie using redirect -maybe combined with AJAX)- instead creating links, I’d be glad about any feedback…

You can’t do this server-side (with PHP), you need to do it client side (with Javascript) opening a new window (with the “” method) for each file.

You can create the list of "" calls in the view using Yii, triggering them at the "onload" event of the page (you can use jQuery for this, or plain Javascript)

HTH, cheers! :)