php利用fsockopen GET/POST提交表单及上传文件,具体内容如下

1.GET

get.php

<"GET ${url} HTTP/1.1\r\n"; 
$out .= "Host: ${host}\r\n"; 
$out .= "Connection:close\r\n\r\n"; 
 
fputs($fp, $out); 
 
// get response 
$response = ''; 
while($row=fread($fp, 4096)){ 
  $response .= $row; 
} 
 
fclose($fp); 
 
$pos = strpos($response, "\r\n\r\n"); 
$response = substr($response, $pos+4); 
 
echo $response; 
"htmlcode">
<"htmlcode">
<"POST ${url} HTTP/1.1\r\n"; 
$out .= "Host:${host}\r\n"; 
$out .= "Content-type:application/x-www-form-urlencoded\r\n"; 
$out .= "Content-length:".strlen($data)."\r\n"; 
$out .= "Connection:close\r\n\r\n"; 
$out .= "${data}"; 
 
fputs($fp, $out); 
 
// get response 
$response = ''; 
while($row=fread($fp, 4096)){ 
  $response .= $row; 
} 
 
fclose($fp); 
 
$pos = strpos($response, "\r\n\r\n"); 
$response = substr($response, $pos+4); 
 
echo $response; 
"htmlcode">
<"upload/'.$filename.'">'; 
"htmlcode">
<"---------------------------".substr(md5(rand(0,32000)),0,10); 
 
$data = "--$boundary\r\n"; 
 
// form data 
foreach($form_data as $key=>$val){ 
  $data .= "Content-Disposition: form-data; name=\"".$key."\"\r\n"; 
  $data .= "Content-type:text/plain\r\n\r\n"; 
  $data .= rawurlencode($val)."\r\n"; 
  $data .= "--$boundary\r\n"; 
} 
 
// file data 
foreach($file_data as $file){ 
  $data .= "Content-Disposition: form-data; name=\"".$file['name']."\"; filename=\"".$file['filename']."\"\r\n"; 
  $data .= "Content-Type: ".mime_content_type($file['path'])."\r\n\r\n"; 
  $data .= implode("",file($file['path']))."\r\n"; 
  $data .= "--$boundary\r\n"; 
} 
 
$data .="--\r\n\r\n"; 
 
$out = "POST ${url} HTTP/1.1\r\n"; 
$out .= "Host:${host}\r\n"; 
$out .= "Content-type:multipart/form-data; boundary=$boundary\r\n"; // multipart/form-data 
$out .= "Content-length:".strlen($data)."\r\n"; 
$out .= "Connection:close\r\n\r\n"; 
$out .= "${data}"; 
 
fputs($fp, $out); 
 
// get response 
$response = ''; 
while($row=fread($fp, 4096)){ 
  $response .= $row; 
} 
 
fclose($fp); 
 
$pos = strpos($response, "\r\n\r\n"); 
$response = substr($response, $pos+4); 
 
echo $response; 
"htmlcode">
<"upload/'.$filename.'">'; 
} 
?> 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

标签:
php,fsockopen,表单,上传文件

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com