douzi9430 2014-12-15 02:20
浏览 29
已采纳

如何在脚本中使用PHP文件的内容?

I am developing the admin panel for my web application. The front end of the site is on a server separate from the admin panel. There is a form in the ACP where I want to be able to change the paths of my assets(img, js, css, etc) so all I have to do is change them in the form. A helper function I created will apply the saved URL to any template assets.

Since the frontend and admin panel are on different servers, I have to use file_get_contents with the FTP protocol to read the assets config file of the frontend from the admin panel. The file_get_contents function gets the content of the assets config file, but I want to be able to parse the actual PHP of the file and not just display the contents.

Example:

This is 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'
    );

How can I use the information from the file above in the file below....

This is my MVC(CodeIgniter) controller:

<?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 ------------------------------------------------/
            /------------------------------------------------------------------------------/

        }

    }

}

I hope I am explaining my problem well enough! Thanks!

  • 写回答

1条回答 默认 最新

  • dongyong1897 2014-12-15 02:31
    关注

    If you have allow_url_fopen and allow_url_include enabled, you can simply use include to include remote file. It is not advisable to do so for security reason, but for the sake of answer your question, you can do something like this.

    include_once('ftps://'.$this->config->item('username') .
                 ':'.$this->config->item('password') . '@' . 
                 $this->config->item('hostname') . 
                 '/application/config/assets.php');
    
    var_dump($config);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 MySQL创建时出现1064以下情况怎么办?
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解
  • ¥15 有偿请教计算电磁学的问题涉及到空间中时域UTD和FDTD算法结合的
  • ¥15 three.js添加后处理以后模型锯齿化严重