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);
    }
  • 相关阅读:
    快速排序
    优先队列
    堆排序
    树、二叉树基础
    分治法
    递归算法详细分析
    算法基础
    Linux文件系统详解
    fs/ext2/inode.c相关函数注释
    块设备的读流程分析
  • 原文地址:https://www.cnblogs.com/xiangxiaodong/p/3421584.html
Copyright © 2011-2022 走看看