Yii Framework Forum: Calling files(documents,pics) from another server - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Calling files(documents,pics) from another server [canceled]

#1 User is offline   tklustig 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 419
  • Joined: 20-April 17
  • Location:Hannover

Posted 10 February 2018 - 08:52 AM

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 = "http://tklustig.ddns.net:1025/img/tklustig.jpg";
        //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 = "http://tklustig.ddns.net:1025/img/Merksatz.docx";
        $url1 = "http://tklustig.ddns.net:1025/img/Uploadlogik.pdf";
        $url2 = "http://tklustig.ddns.net:1025/img/Netzwerk.txt";
        $this->redirect([$url]);
    }


First url(Merksatz.docx) will be shown starting MSOffice, without influencing application in a special tab
That's what I want!
Second and third url will replace application in tab instead starting Adobe or another EditorPosted Image

That's, want i don't want!
Is there a way to open all documents in a different/special tab?
0

#2 User is offline   tklustig 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 419
  • Joined: 20-April 17
  • Location:Hannover

Posted 10 February 2018 - 12:07 PM

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

    public function actionFile() {
        $url1 = "http://tklustig.ddns.net:1025/img/Merksatz.docx";
        $url2 = "http://tklustig.ddns.net:1025/img/Uploadlogik.pdf";
        $url3 = "http://tklustig.ddns.net:1025/img/Netzwerk.txt";
        $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....
0

#3 User is offline   Silvio Porcellana 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 31-January 18

Posted 13 February 2018 - 06:19 PM

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

You can create the list of "window.open" 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! :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users