![](/img/trans.png)
[英]how can I use the function of file_get_contents in php to read the file content in a specific folder?
[英]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_fopen
和allow_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.