php另类上传图片的方法(PHP用Socket上传图片)
服务器端:
<?php
set_time_limit(10);
//* 设置不显示任何错误 */
//error_reporting(0);
function varinfo($str) {
echo "<pre>";
var_dump($str);
echo "<pre>";
}
$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);
?>
客户端:
<?php
$errno='001';
$errstr="socket file error";
$fp = fsockopen("192.168.3.57", 1337, $errno, $errstr, 10);
if (!$fp) {
echo "$errstr ($errno)<br />\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);
?>
上一篇: 芭蕉空腹吃的危害是很大的哦!
下一篇: C4D物体怎么以边或者中心旋转?
推荐阅读
-
PHP批量上传图片的具体实现方式_PHP教程
-
php使用curl模拟浏览器表单上传文件或者图片的方法
-
CodeIgniter上传图片成功的全部过程分享_PHP教程
-
上传图片的时候,就弹出选择本map">
求php+ajax上传图片的实例!用的不是files,点击上传图片的时候,就弹出选择本map
-
php修改上传图片尺寸的方法,
-
mysql - php上传含中文名的图片失败问题
-
php修改上传图片尺寸的方法,_PHP教程
-
jcrop插件+php实现的图片上传与裁剪
-
php ckeditor上传图片文件名乱码解决方法_PHP
-
php 文件上传类与图片处理类的实现代码