簡體   English   中英

如何在腳本中使用PHP文件的內容?

[英]How can I use the contents of a PHP file in my script?

我正在為我的Web應用程序開發管理面板。 該站點的前端位於與管理面板分開的服務器上。 ACP中有一個表單,我希望能夠更改資產(img,js,css等)的路徑,因此我要做的就是在表單中更改它們。 我創建的輔助函數會將保存的URL應用於任何模板資產。

由於前端和管理面板位於不同的服務器上,因此我必須使用帶有FTP協議的file_get_contents來從管理面板讀取前端的資產配置文件。 file_get_contents函數獲取資產配置文件的內容,但我希望能夠解析該文件的實際PHP,而不僅僅是顯示內容。

例:

這是config / assets.php

<?php

$config = array(
    'img' => 'http://localhost/frontend/assets/img',
    'css' => 'http://localhost/frontend/assets/css',
    'js' => 'http://localhost/frontend/assets/js',
    'attachments' => 'http://localhost/frontend/attachments'
    );

如何使用下面文件中的上述文件中的信息。

這是我的MVC(CodeIgniter)控制器:

<?php

class Assets extends MY_Controller {

    function index(){

        $this->load->library('form_validation');
        if($this->form_validation->run('assets') == FALSE){

            $this->template->overall_header("Asset Configuration");

            $this->load->config('assets');

            $config['acp'] = array(
                    'img_url' => $this->config->item('img_url'),
                    'css_url' => $this->config->item('css_url'),
                    'js_url' => $this->config->item('js_url'),
                    'attachment_url' => $this->config->item('attachment_url')
                    );

            $this->load->config('ftp_frontend');
            $content = file_get_contents('ftps://'.$this->config->item('username').':'.$this->config->item('password').'@'.$this->config->item('hostname').'/application/config/assets.php');

            /------------------------------------------------------------------------------/
            /-----  Pass variables to the admin cp form from the content of the front -----/
            /-----  end assets config file ------------------------------------------------/
            /------------------------------------------------------------------------------/

        }

    }

}

我希望我能很好地解釋我的問題! 謝謝!

如果啟用了allow_url_fopenallow_url_include ,則可以簡單地使用include包括遠程文件。 出於安全考慮,不建議這樣做,但是為了回答您的問題,您可以執行以下操作。

include_once('ftps://'.$this->config->item('username') .
             ':'.$this->config->item('password') . '@' . 
             $this->config->item('hostname') . 
             '/application/config/assets.php');

var_dump($config);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM