时时商务社区
标题:
php另类上传图片的方法(PHP用Socket上传图片)
[打印本页]
作者:
网络通达
时间:
2018-2-14 08:11
服务器端:
[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图片上传类详解
欢迎光临 时时商务社区 (http://bbs.4435.cn/)
Powered by Discuz! X3.2