从远程PHP文件更新本地PHP文件 [英] Update local php file from remote php file

查看:873
本文介绍了从远程PHP文件更新本地PHP文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为许多客户端安装一个CMS,但随着我不断改进它,我对几个文件进行修改。我想让这些更新自动应用于使用相同文件的所有项目。

I am working on a CMS that will be installed for many clients, but as I keep on improving it I make modifications to a few files. I want these updates to be automatically applied to all the projects using the same files.

我想到每次打开CMS时都执行一个检查文件。这个文件会比较本地文件的版本与远程文件,为此我可以保留一个日志或东西的版本,没有什么大不了,但这不是问题,这里是一些示例代码我想到:

I thought of executing a check file every time the CMS is opened. This file would compare the version of the local file with the remote file, for this I can keep a log or something for the versions, no big deal, but that's not the problem, here is some sample code I thought of:

$url = 'http://www.example.com/myfile.php';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
$data = curl_exec($curl);
curl_close($curl);

问题是得到 myfile.php 因为它的PHP文件服务器将执行它并返回输出,但我想要的文件的实际内容。我明白,这是不可能的,因为这将是一个安全问题,任何人都能够获得其他网站的PHP代码,但有什么办法获得远程PHP文件的内容可能通过给予远程的特殊权限

The problem is getting the content of myfile.php since its a PHP file the server will execute it and return the output, but I want the actual content of the file. I understand that this is not possible as it would be a security problem, anybody would be able to get the php code of other sites, but is there any way to get the contents of a remote php file maybe by giving special permissions to a remote connection?

感谢。

推荐答案

在您的远程服务器上,将使用readfile()返回原始的php代码。

You should create a download script on your remote server which will return the original php code by using readfile().

<?php
$file = $_SERVER['DOCUMENT_ROOT'] . $_GET['file'];

// @TODO: Add security check if file is of type php and below document root. Use realpath() to check this.
header("Content-Type: text/plain");
header("Content-Disposition: attachment; filename=\"$file\"");
readfile($file);
?>

通过fethcing http://example.com/download获取文件内容。 php?file = fileName

Get file contents by fethcing http://example.com/download.php?file=fileName

这篇关于从远程PHP文件更新本地PHP文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆