XChinux's Home

过往资料可到百度空间http://hi.baidu.com/xchinux

http://www.qtcn.org/bbs/u/2  [收藏] [复制]

XChinux

爱Qt,爱N9,qtcn.org

  • 632

    关注

  • 2178

    粉丝

  • 6397

    访客

  • 等级:光明使者
  • 身份:总版主
  • 总积分:11224
  • 男,1979-01-01
  • 山西

最后登录:2024-01-27

更多资料

日志

用PHP(SOCKET) POST二进制文件

2011-06-12 12:45

2009-05-23  22:59
<?php
$bondary = "---------------------------7d4a6d158c9";

$body = "--" . $bondary . "\r\n";
$body .= "Content-Disposition: form-data; name=\"data\"; filename=\"test.data\"\r\n";
$body .= "Content-Type: application/octet-stream\r\n\r\n";

$end_body = "\r\n--" . $bondary . "--\r\n";

$file = file_get_contents("test.data");


$header = "POST /myserver/upload.php HTTP/1.1\r\n";
$header .= "Host: localhost\r\n";
$header .= "Content-Type: multipart/form-data; boundary=" . $bondary . "\r\n";
$header .= "Content-Length: " . (strlen($body) + strlen($file) + strlen($end_body)) . "\r\n\r\n";


$sock = fsockopen("localhost", 80);
fwrite($sock, $header);
fwrite($sock, $body);
fwrite($sock, $file);
fwrite($sock, $end_body);
while (!feof($sock))
{
      echo(fgets($sock));
}
fclose($sock);
分类:编程技术|回复:0|浏览:2173|全站可见|转载
 

Powered by phpwind v8.7 Certificate Copyright Time now is:05-03 15:38
©2005-2016 QTCN开发网 版权所有 Gzip disabled