appserv 的php多版本下载工具

#!/usr/bin/env php
<?php

/**
 * AppServ的php下载工具
 * 需要安装wget for windowns 工具 网站
 * http://www.gnu.org/software/wget/
 * 为了避免每次重新爬去文件列表,已定义$config中
 */


//已获取的文件列表,详见附件
$config = [];
//官网
$host ='https://windows.php.net/downloads/releases/archives/';
//保存路径
$save_path ="E:/AppServ/download/";
//powershell
$powershell_path ="C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe";

// +----------------------------------------------------------------------
// / 程序执行流程
// +----------------------------------------------------------------------
echo "\n  AppServ的php下载工具 v1.0\n\n";
echo "\n请输入版本号: ";
$search_str = strtolower(trim(fgets(STDIN)));
$res =[];
$i=0;
if(!empty($search_str)){
    foreach($config as $filename){
        if( strpos($filename,$search_str) !== false){
            $res[] = $filename;
            echo "[$i]    ".$filename."\n";
            $i++;
        }
    }
    if(!empty($res)){
        echo "\n请请输入你想要下载文件序号: ";
        $file_number = strtolower(trim(fgets(STDIN)));
        if(isset($file_number) and !empty($file_number) and isset($res[$file_number])){
            echo "\n开始下载".$res[$file_number];
            download($res[$file_number]);
            echo "下载完毕\n";
        }
    }else{
        echo "\n没有查询到文件";
        die();
    }
   
}

/**
 * 获取版本号
 */
function get_version($file_name){
    preg_match_all("/(([0-9]|([1-9]([0-9]*))){1,2}.){2}([0-9]|([1-9]([0-9]*))){1,2}/",$file_name,$version);
    if(isset($version) and empty($version)){
        return $version[0][0];
    }
}
/**
 * 下载文件
 */
function download($file,$path ="E:/AppServ/download/"){
    global $host,$save_path,$powershell_path;
    shell_exec("$powershell_path clear");
    shell_exec("$powershell_path wget  ".$host."/".$file." -o ".$path.$file);
}
/**
 * 从html中获取官网文件列表
 */
function get_files($str){
    // $str =file_get_contents("a.txt");
    preg_match_all("/href=\"([^\"]+)\"/ims",$str,$link);
    $files =[];
     foreach($link[0] as $name){
        $name =str_replace("\"",'',$name);
        $path =str_replace("href=/",'',$name);
         if(strpos($path,"downloads/releases/archives/php-") !==false){
            $arr=explode("/",$path);
            $file_name = end($arr);
            $files[] =$file_name;
            $file_name ='';
         }
     }
    return  $files;
}
This entry was posted in 未分类. Bookmark the permalink.

发表回复