首页 > php教程 > php手册 > php用socket上传图片

php用socket上传图片

WBOY
发布: 2016-06-06 19:52:28
原创
872 人浏览过

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 服务器端: ?php set_time_limit(10); //* 设置不显示任何错误 */ //error_reporting(0); function varinfo($str) { echo "pre"; var_dump($str); echo "pre"; } $commonProtocol = getprotobyname("

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  服务器端:

  

  set_time_limit(10);

  //* 设置不显示任何错误 */

  //error_reporting(0);

  function varinfo($str) {

  echo "

";

  var_dump($str);

  echo "

";

  }

  $commonProtocol = getprotobyname("tcp");

  $socket = socket_create(AF_INET, SOCK_STREAM, $commonProtocol);

  if ($socket) {

  $result = socket_bind($socket, '192.168.3.57', 1337);

  if ($result) {

  $result = socket_listen($socket, 5);

  if ($result) {

  echo "监听成功";

  }

  }

  }else{

  echo "监听失败";

  }

  //$path = "/home/upload/";

  $path = "e://web//";

  while (true)

  {

  $connection = socket_accept($socket);

  if($connection)

  {

  $msg = "telnet succeed!rn";

  socket_write($connection, $msg, strlen($msg));

  $BufferPond = array();

  $buffer = '';

  while($flag = socket_recv($connection, $buffer, 1024, 0))

  {

  if (false !== strpos($buffer,'filename:'))

  {

  $filename = substr($buffer,9);

  $filename = $path.$filename;

  $fp = fopen($filename,"wb");

  continue;

  }

  fwrite($fp,$buffer);

  }

  fclose($fp);

  socket_close($connection);

  }

  }

  socket_close($socket);

  ?>

  客户端:

  

  $errno='001';

  $errstr="socket file error";

  $fp = fsockopen("192.168.3.57", 1337, $errno, $errstr, 10);

  if (!$fp) {

  echo "$errstr ($errno)
n";

  } else {

  $str = "filename:socket_file.bmp";

  fwrite($fp, $str);    $out = file_get_contents('../../iphone3G.bmp');

  if($out){

  fwrite($fp, $out);

  fwrite($fp,'over');

  echo "上传成功";

  }

  }

  fclose($fp);

  ?>

php用socket上传图片

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板