php另类上传图片的方法(PHP用Socket上传图片)
复制代码 代码如下:
set_time_limit(10);
//* 设置不显示任何错误 */
//error_reporting(0);
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);
?>
客户端:复制代码 代码如下:
$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);
?>
推荐阅读
-
PHP批量上传图片的具体实现方式_PHP教程
-
php简单实现批量上传图片的方法_PHP
-
上传图片的时候,就弹出选择本map">
求php+ajax上传图片的实例!用的不是files,点击上传图片的时候,就弹出选择本map
-
PHP上传图片的好插件
-
一个完整的PHP图片上传,生成缩略图,插入数据库代码流程_PHP教程
-
PHP限制图片上传的格式
-
php getimagesize 上传图片的长度和宽度检测代码_PHP
-
PHP上传图片时生成缩微图象的函数
-
PHP设置图片文件上传大小的具体实现方法_PHP
-
PHP swfupload图片上传的实例代码_PHP教程