php另类上传图片的方法(PHP用Socket上传图片)_php实例

WBOY
Release: 2016-05-17 08:53:57
Original
995 people have browsed it


服务器端:

复制代码 代码如下:

set_time_limit(10);
//* 设置不显示任何错误 */
//error_reporting(0);

function varinfo($str) {
echo "

";<br>var_dump($str);<br>echo "<pre class="brush:php;toolbar:false">";<br>}
<p>$commonProtocol = getprotobyname("tcp");<br>$socket = socket_create(AF_INET, SOCK_STREAM, $commonProtocol);<br>if ($socket) {<br>$result = socket_bind($socket, '192.168.3.57', 1337);<br>if ($result) {<br>   $result = socket_listen($socket, 5);<br>   if ($result) {<br>    echo "监听成功";<br>   }<br>}<br>}else{<br>echo "监听失败";<br>}</p>
<p>//$path = "/home/upload/";<br>$path = "e://web//";</p>
<p>while (true)   {   <br>$connection = socket_accept($socket);<br>if($connection){   <br>   $msg = "telnet succeed!\r\n";<br>   socket_write($connection, $msg, strlen($msg)); <br><br>     $BufferPond = array();   <br>     $buffer = '';</p>
<p>     while($flag = socket_recv($connection, $buffer, 1024, 0)){    <br>          if (false !== strpos($buffer,'filename:')){   <br>             $filename = substr($buffer,9);<br>             $filename = $path.$filename;<br>             $fp = fopen($filename,"wb");<br>             continue;    <br>          }    <br>        fwrite($fp,$buffer);<br>     }<br>     fclose($fp);<br>     socket_close($connection);    <br>}    <br>}    <br>socket_close($socket);   <br>?><br></p>
Copy after login

客户端:
复制代码 代码如下:

$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);
?>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!