【发布时间】:2020-09-09 21:50:21
【问题描述】:
我正在制作一个自动更新系统,但在弄清楚如何将 ZIP 文件下载并解压缩到我的服务器上时遇到了一些麻烦。我不知道是使用 cURL 还是 file_get_contents。到目前为止,我的代码可以检查正确的版本并显示一个对话框。我的代码如下。
<?php
function check_for_updates(){
$phoenix_version = '1.0.0';
$rc = @fsockopen("www.phoenix.ltda", 80, $errno, $errstr, 1);
if (is_resource($rc)) {
define('REMOTE_VERSION', 'https://phoenix.ltda/updates/version.txt');
$remote_version=trim(file_get_contents(REMOTE_VERSION));
$remote_version = preg_replace('/[^\\d.]+/', '', $remote_version);
if(version_compare($remote_version, $phoenix_version) == 1){
echo 'New Version Detected!';
}
}
}
}
check_for_updates();
?>
如何使用 PHP 从我的服务器获取更新 ZIP 并将其提取到根目录(public_html 或 httpdocs)?其他问题只提到了读取 ZIP 文件。
【问题讨论】:
-
您可能想检查其他问题,例如stackoverflow.com/questions/3938534/…
-
cURL 或 file_get_contents:取决于您需要随请求发送的内容,file_get_contents 仅支持基本请求。您需要将纯粹的 $remote_version 保存到具有 file_put_contents 或类似文件的文件中,然后使用 php.net/manual/en/ziparchive.extractto.php 解压缩。摆脱那个 trim/preg_replace 垃圾。摆脱那个无用的定义。
标签: php file-get-contents