从远程 php 文件更新本地 php 文件

Update local php file from remote php file

我正在开发一个将为许多客户安装的 CMS,但随着我不断改进它,我对一些文件进行了修改。我希望这些更新自动应用到所有使用相同文件的项目。

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

$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 文件,服务器将执行它并 return 输出,但我想要文件的实际内容。我知道这是不可能的,因为这是一个安全问题,任何人都可以获取其他站点的 php 代码,但是有什么方法可以获取远程 php 文件的内容或许通过授予远程连接特殊权限?

谢谢。

您应该在远程服务器上创建一个下载脚本,它将 return 使用 readfile() 的原始 php 代码。

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