php另类上传图片的方法(PHP用Socket上传图片)_PHP

WBOY
發布: 2016-06-01 11:58:21
原創
825 人瀏覽過


服务器端:
复制代码 代码如下:
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><br>客户端:<br><u>复制代码</u> 代码如下:<br><?php <BR>$errno='001';<br>$errstr="socket file error";</p>
<p>$fp = fsockopen("192.168.3.57", 1337, $errno, $errstr, 10);<br>if (!$fp) {    <br>    echo "$errstr ($errno)<br>\n";    <br>} else {    <br>    $str = "filename:socket_file.bmp";    <br>    fwrite($fp, $str);    $out = file_get_contents('../../iphone3G.bmp');    <br>   if($out){<br>    fwrite($fp, $out);    <br>    fwrite($fp,'over');<br>   echo "上传成功";<br>   }<br><br>}<br>fclose($fp);<br>?><br></p>
    
登入後複製
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!