zoukankan      html  css  js  c++  java
  • php Socket模拟表单上传文件函数_学习

    模拟上传文件的php代码
    里面访问地址、主机、上传文件名、内容、分隔符可以修改
     
    function postFile($file) {
        $clf = " ";  
        $postHeader = "";
        $postHeader .= "POST /study/post/post.php HTTP/1.1" . $clf;
        $postHeader .= "Host: 127.0.0.1:80" . $clf;
        $postHeader .= "Connection: close" . $clf;
       $postHeader .= "Content-type: multipart/form-data, boundary=---------------------17d079a010" . $clf;
     
        $postData = "";
        $postData .= "-----------------------17d079a010" . $clf;
        $postData .= "Content-Disposition: form-data; name="key"" . $clf . $clf;
        $postData .= date('Y/m/d/') . "{$file}" . $clf;
        $postData .= "-----------------------17d079a010" . $clf;
        $postData .= "Content-Disposition: form-data; name="file"; filename={$file}" . $clf;
     
     
        $postData .= "Content-Type: text/html" . $clf . $clf;
        $postData .= "test post" . $clf;
        $postData .= "-----------------------17d079a010--";
       
        $postHeader .= "Content-length: " . strlen($postData) . $clf . $clf;
     
        //echo $postData;exit;
        ini_set('auto_detect_line_endings', 1);
        //链接远程服务器
        $fp = fsockopen("127.0.0.1", 80);
     
        //发送数据
        fputs($fp, $postHeader.$postData);
     
        //显示服务器返回数据
        while (!feof($fp)) {
            echo fgets($fp);
        }
     
        //关闭服务器连接
        fclose($fp);
    }
  • 相关阅读:
    表操作之数据类型——日期类型
    cocos2dx tableView 的使用
    lua中的循环
    lua中 后端发过来的 按位表示值,在前端中需要处理的函数
    lua 打印表方法
    近况
    lua开发
    4)数据结构和算法学习_链表
    3)数据结构和算法学习_链表
    使用VsCode断点调试TS
  • 原文地址:https://www.cnblogs.com/xiangxiaodong/p/3421584.html
Copyright © 2011-2022 走看看