模拟文本:
$username='admin';
$password='admin';
$fp=fsockopen('www.pooy.net','80',$errno,$errstr,
1);
$post="username=$username&password=$password";
if(!$fp)
{
echo"$errstr
($errno)<br />\n";
}else{
$out="POST
/SJzgImgEdit/login HTTP/1.1\r\n";
$out.="Host:
www.pooy.net\r\n";
$out.='User-Agent:
Mozilla/5.0 (Windows NT 5.1; rv:8.0.1) Gecko/20100101 Firefox/8.0.1 FirePHP/0.6'."\r\n";
$out.='Content-Type:
application/x-www-form-urlencoded'
."\r\n";
$out.='Content-Length:
'.strlen($post)."\r\n";
$out.="Connection:
Close\r\n\r\n";
$out.=$post."\r\n";
fwrite($fp,$out);
while(!feof($fp))
{
echofgets($fp,
128);
}
fclose($fp);
}
CURL POST 上传文件(模拟页面)
define(
'UPLOAD_IMG'
,
'http://www.pooy.net/Snoopy/upload.php'
);
function
upload_curl_pic(
$file
)
{
$url
=
UPLOAD_IMG;
$fields
[
'f'
]
=
'@'
.
$file
;
$ch
=
curl_init();
curl_setopt(
$ch
,
CURLOPT_URL,
$url
);
curl_setopt(
$ch
,
CURLOPT_POST, 1 );
curl_setopt(
$ch
,
CURLOPT_POSTFIELDS,
$fields
);
ob_start();
curl_exec(
$ch
);
$result
=
ob_get_contents();
ob_end_clean();
curl_close(
$ch
);
return
$result
;
}
$file
=
'H:\www\test\psuCARGLSPA-pola.jpg'
;
//要上传的文件
$src
=
upload_curl_pic(
$file
);
echo
$src
;
CURL POST 上传文件(处理页面)
header(
"content-type:text/html;charset=utf-8"
);
//防止上传
//$file=$_FILES['f'];
//var_dump($file);
exit
();
$uploaddir
=
"H:/www/test/Snoopy/test/"
;
$uploadfile
=
$uploaddir
.
$_FILES
[
'f'
][
'name'
];
if
(move_uploaded_file(
$_FILES
[
'f'
][
'tmp_name'
],
$uploadfile
))
{
echo
$uploadfile
;
//echo
"File is valid, and was successfully uploaded.\n";
}
else
{
echo
'0'
;
//echo
"Possible file upload attack!\n";
//echo
'Here is some more debugging info:';
}
转载:http://www.oschina.net/question/553727_69528