• php file_get_contents 使用3法


    <?php
    //GET
    function http_get($url, $params){
        return file_get_contents($url.'?'.http_build_query($params));
    }
    //POST
    function http_post($url, $params){
        $eol = "
    ";
        $content = http_build_query ($params);
        $header = 'Content-type: application/x-www-form-urlencoded'.$eol.
                  "Content-Length: " . strlen($content).$eol;
        $opts = array('http' =>
            array(
                'method'  => 'POST',
                'header'  => $header,
                'content' => $content
            )
        );
        $context  = stream_context_create($opts);
        return file_get_contents($url, false, $context);
    }
    //UPLOAD
    function http_upload($url, $file){
        $MULTIPART_BOUNDARY = '--------------------------'.microtime(true);
        $FORM_FIELD = 'uploaded_file';
        $header = 'Content-Type: multipart/form-data; boundary='.$MULTIPART_BOUNDARY;
        $content =  "--".$MULTIPART_BOUNDARY."
    ".
            "Content-Disposition: form-data; name="".$FORM_FIELD.""; file="".basename($file).""
    ".
            "Content-Type: application/zip
    
    ".
            file_get_contents($file)."
    ".
            "--".$MULTIPART_BOUNDARY."--
    ";
        $context = stream_context_create(array(
            'http' => array(
                'method' => 'POST',
                'header' => $header,
                'content' => $content,
            )
        ));
        return file_get_contents($url, false, $context);
    }
    ?>
  • 相关阅读:
    docker中 启动所有的容器命令
    使用Docker部署服务
    docker常规操作——启动、停止、重启容器实例
    Docker Swarm 常用命令
    ArcGIS中search窗口不能查询解决办法
    ylpy
    第7章
    ArcGIS 将模型导出为 Python 脚本
    11章代码
    9章代码
  • 原文地址:https://www.cnblogs.com/coffee_cn/p/3810377.html
Copyright © 2020-2023  润新知