模拟上传文件的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);
}