日期:2010-09-03 11:28:00 来源:本站整理
php用socket上传图片的办法[网站编程]
本文“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 ($resul[separator]t) {
$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);
?>
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 ($resul[separator]t) {
$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);
?>
$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);
?>
利用办法
办法一:
<?php
$GoTo="index.php";// 假如这里的目标链接取自数据库就实现了动态转向
header(sprintf("Location: %s", $GoTo));
?>
$GoTo="index.php";// 假如这里的目标链接取自数据库就实现了动态转向
header(sprintf("Location: %s", $GoTo));
?>
办法二:
<?php echo "<script>window.location =/"$PHP_SELF/";</script>";?>
办法三:
<?php echo "<META HTTP-EQUIV=/"Refresh/" CONTENT=/"0;URL=index.php/">";?>
以上是“php用socket上传图片的办法[网站编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |
评论内容只代表网友观点,与本站立场无关!
评论摘要(共 0 条,得分 0 分,平均 0 分)
查看完整评论