[英]How can I use the contents of a PHP file in my script?
I am developing the admin panel for my web application. 我正在为我的Web应用程序开发管理面板。 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.
ACP中有一个表单,我希望能够更改资产(img,js,css等)的路径,因此我要做的就是在表单中更改它们。 A helper function I created will apply the saved URL to any template assets.
我创建的辅助函数会将保存的URL应用于任何模板资产。
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. 由于前端和管理面板位于不同的服务器上,因此我必须使用带有FTP协议的file_get_contents来从管理面板读取前端的资产配置文件。 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.
file_get_contents函数获取资产配置文件的内容,但我希望能够解析该文件的实际PHP,而不仅仅是显示内容。
Example: 例:
This is config/assets.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'
);
How can I use the information from the file above in the file below.... 如何使用下面文件中的上述文件中的信息。
This is my MVC(CodeIgniter) controller: 这是我的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 ------------------------------------------------/
/------------------------------------------------------------------------------/
}
}
}
I hope I am explaining my problem well enough! 我希望我能很好地解释我的问题! Thanks!
谢谢!
If you have allow_url_fopen
and allow_url_include
enabled, you can simply use include
to include remote file. 如果启用了
allow_url_fopen
和allow_url_include
,则可以简单地使用include
包括远程文件。 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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.