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

php用socket上传图片

WBOY
WBOY原創
2016-06-06 19:52:28866瀏覽

欢迎进入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 "

";
<p>  var_dump($str);</p>
<p>  echo "</p><pre class="brush:php;toolbar:false">";
<p>  }</p>
<p>  $commonProtocol = getprotobyname("tcp");</p>
<p>  $socket = socket_create(AF_INET, SOCK_STREAM, $commonProtocol);</p>
<p>  if ($socket) {</p>
<p>  $result = socket_bind($socket, '192.168.3.57', 1337);</p>
<p>  if ($result) {</p>
<p>  $result = socket_listen($socket, 5);</p>
<p>  if ($result) {</p>
<p>  echo "监听成功";</p>
<p>  }</p>
<p>  }</p>
<p>  }else{</p>
<p>  echo "监听失败";</p>
<p>  }</p>
<p>  //$path = "/home/upload/";</p>
<p>  $path = "e://web//";</p>
<p>  while (true)</p>
<p>  {</p>
<p>  $connection = socket_accept($socket);</p>
<p>  if($connection)</p>
<p>  {</p>
<p>  $msg = "telnet succeed!\r\n";</p>
<p>  socket_write($connection, $msg, strlen($msg));</p>
<p>  $BufferPond = array();</p>
<p>  $buffer = '';</p>
<p>  while($flag = socket_recv($connection, $buffer, 1024, 0))</p>
<p>  {</p>
<p>  if (false !== strpos($buffer,'filename:'))</p>
<p>  {</p>
<p>  $filename = substr($buffer,9);</p>
<p>  $filename = $path.$filename;</p>
<p>  $fp = fopen($filename,"wb");</p>
<p>  continue;</p>
<p>  }</p>
<p>  fwrite($fp,$buffer);</p>
<p>  }</p>
<p>  fclose($fp);</p>
<p>  socket_close($connection);</p>
<p>  }</p>
<p>  }</p>
<p>  socket_close($socket);</p>
<p>  ?></p>
<p>  客户端:</p>
<p>  <?php </P>
</p><p>  $errno='001';</p>
<p>  $errstr="socket file error";</p>
<p>  $fp = fsockopen("192.168.3.57", 1337, $errno, $errstr, 10);</p>
<p>  if (!$fp) {</p>
<p>  echo "$errstr ($errno)<br>\n";</p>
<p>  } else {</p>
<p>  $str = "filename:socket_file.bmp";</p>
<p>  fwrite($fp, $str);    $out = file_get_contents('../../iphone3G.bmp');</p>
<p>  if($out){</p>
<p>  fwrite($fp, $out);</p>
<p>  fwrite($fp,'over');</p>
<p>  echo "上传成功";</p>
<p>  }</p>
<p>  }</p>
<p>  fclose($fp);</p>
<p>  ?></p> <p>

<img  src="/inc/test.jsp?url=http%3A%2F%2Fwww.chinaitlab.com%2Fcms%2Fimages%2Flogo14.gif&refer=http%3A%2F%2FLinux.chinaitlab.com%2FPHP%2F839935.html" alt="php用socket上传图片" ></p>


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn