|
服务器端:
[U]复制代码[/U] 代码如下:
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!\r\n";
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);
?>
客户端:
[U]复制代码[/U] 代码如下:
$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图片上传类带图片显示php 图片上传类代码php 图片加水印与上传图片加水印php类超级好用的一个php上传图片类(随机名,缩略图,加水印)PHP实现多图片上传类实例php上传图片类及用法示例php图片上传类 附调用方法PHP上传图片类显示缩略图功能PHP之图片上传类实例代码(加了缩略图)php封装的单文件(图片)上传类完整实例PHP实现原生态图片上传封装类方法php版阿里云OSS图片上传类详解
|
|