ajax php仿网易文章评论顶一下效果
ajax php教程仿网易文章评论顶一下效果
<div class='plding fr'>
<a href='action.php?id="1&action=top_num'>顶一下</a>[5]
</div>
js ajax
<script language="网页特效" type="text/javascript">
<!--
// ajax检测评论是否已经支持过了
function getcookie(c_name){ //检测cookie
if (document.cookie.length>0){
c_start=document.cookie.indexof(c_name + "=")
if(c_start!=-1){
c_start=c_start + c_name.length+1;
c_end=document.cookie.indexof(";",c_start);
if(c_end==-1) c_end=document.cookie.length;
return unescape(document.cookie.substring(c_start,c_end));
}
}
return "";
}function setcookie(c_name,value,expiredays){ //设置cookie
var exdate=new date();
exdate.setdate(exdate.getdate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.togmtstring());
}function createxmlhttprequest(){ //创建xmlhttprequest对象
if(window.activexobject){ //ie
try {
return new activexobject("microsoft.xmlhttp");
} catch(e){
return;
}
}else if(window.xmlhttprequest){ //mozilla,firefox
try {
return new xmlhttprequest();
} catch(e){
return;
}
}
}function get_top_num(id){ //主调函数
var get_top_cookie=getcookie('get_top_'+id+'_cookie');
if(get_top_cookie!=null && get_top_cookie!=""){
alert('此条评论你已经支持过了');
}
else{
var xmlhttp=createxmlhttprequest();
var url = "action.php?action=top_num&id="+id;
if (id==""){
return false ;
}
if (xmlhttp){
callback = getreadystatehandler(xmlhttp,id);
xmlhttp.onreadystatechange = callback;
xmlhttp.open("get", url,true);
xmlhttp.send(null);
}
setcookie('get_top_'+id+'_cookie','istop',1);
}
}function getreadystatehandler(xmlhttp,id){ //服务器返回后处理函数
var top_num = document.getelementbyid("top_num_"+id).innerhtml;
return function (){
if(xmlhttp.readystate == 4){
if(xmlhttp.status == 200){
if (xmlhttp.responsetext==1){
document.getelementbyid("top_num_"+id).innerhtml=number(top_num)+1;
}
}
}
}
}//-->
</script>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>关键字百度排名批量查</title>
<base target="_blank" />
<meta http-equiv="x-ua-compatible" content="ie=emulateie7" />
<style type="text/css教程">
body{margin:0;padding:0;background:#fff;color:#000;font:12px 微软雅黑, verdana, tahoma, lucida grande, arial, sans-serif;text-align:center;}
#wrapper{width:990px;margin:0 auto;line-height:20px;text-align:left;}
#header,#main,#footer{clear:both;float:left;margin:10px 0 0 0;width:100%;}
a,a:visited{color:#0196e3;text-decoration:none;}
form{margin:10px;}
.kinput{width:300px;margin:0 5px;padding:2px;text-align:left;border:1px solid #ccc;font-weight:bold;}
.kbutton{width:80px;margin:0 5px;padding:2px;height:20px;}
#kgrid{float:left;width:100%;}
.s_kw,.s_rank,.s_wt,.s_title,.s_cache,.s_feng,.s_baidu,.s_mu{float:left;height:30px;line-height:30px;overflow:hidden;text-align:left;border:1px solid #c2d5e3;}
.s_bar{clear:both;float:left;width:100%;height:30px;line-height:30px;text-align:center;}
.s_kw{clear:both;width:120px;}
.s_rank{width:30px;}
.s_wt{width:50px;color:#0e774a;}
.s_title{width:340px;}
.s_cache{width:80px;}
.s_feng{width:80px;}
.s_baidu{width:150px;}
.s_mu{width:120px;}
</style>
</head><body>
<div id="wrapper">
<?php教程
function tongji()
{
$myhost = $_server['http_host'];
if (preg_match("/(www.)?baiek.com/i", $myhost, $myout))
{
echo '<script language="网页特效" type="text/javascript" src="http://js.users.51.la/4295418.js"></script>';
}
}function libxml_display_error($error)
{
$return = "<br/>n";
switch ($error->level)
{
case libxml_err_warning:
$return .= "<b>warning $error->code</b>: ";
break;
case libxml_err_error:
$return .= "<b>error $error->code</b>: ";
break;
case libxml_err_fatal:
$return .= "<b>fatal error $error->code</b>: ";
break;
}
$return .= trim($error->message);
if ($error->file)
{
$return .= " in <b>$error->file</b>";
}
$return .= " on line <b>$error->line</b>n";
return $return;
}function libxml_display_errors()
{
$errors = libxml_get_errors();
foreach ($errors as $error)
{
print libxml_display_error($error);
}
libxml_clear_errors();
}$kfname = '';
if (isset($_get['kf']))
{
$kfname = trim($_get['kf']);
}
$version = '<script language="javascript" type="text/javascript" src="http://www.111cn.net/version.js"></script>';
echo <<< eoth
<div id="header">
做企业站或认识企业站的朋友,请支持一下我的小站 <a href="http://www.198114.com/"><b>198114产品企业分类目录</b></a>,多谢多谢!!
<a href="http://www.111cn.net/" target="_self"><h1>关键字百度排名批量查询(php网页版) baiek.com</h1></a>
<form method="get" target="_self">
<input id="kf" name="kf" type="text" class="kinput" value="{$kfname}" />
<input id="submitbtn" type="submit" class="kbutton" value="批量查询" />
 <a href="http://www.111cn.net/baiek.rar" target="_self"><b>点击此处下载(更新于{$version})</b></a>
 在线演示:<a href="http://www.111cn.net/?kf=kw1.xml" target="_self">演示1</a> <a href="http://www.111cn.net/?kf=kw2.xml" target="_self">演示2</a> <a href="http://www.111cn.net/?kf=kw3.xml" target="_self">演示3</a>
</form>
</div>eoth;
if (!file_exists($kfname) || !is_readable($kfname))
{
tongji();
exit('请输入正确的关键字清单文件(xml格式,请参考<a href="http://www.111cn.net/readme.txt">readme</a>文件)!!');
}
libxml_use_internal_errors(true);
$doc = new domdocument();
$doc->load($kfname);
if (!$doc->schemavalidate('kw.xsd'))
{
print '<b>关键字列表xml文件发现错误!</b>';
libxml_display_errors();
tongji();
exit;
}//由xml文件提取关键字列表与相应的域名
$kwlist = array(); $g = 1;
$kgroups教程 = $doc->getelementsbytagname("kgroup");
foreach ($kgroups as $kgroup)
{
$kwlist[$g]['domain'] = trim($kgroup->getelementsbytagname("kdomain")->item(0)->nodevalue);
$kwords = $kgroup->getelementsbytagname("kword");
$w = 1;
foreach ($kwords as $kword)
{
if ($kword->haschildnodes())
{
$kwlist[$g]['kword'][$w] = trim($kword->firstchild->nodevalue);
}
$w++;
}
$g++;
}
?>
<div id="main">
<?php
function get_dm_weight($h, $i)
{
//$h表示搜索结果的url,$i表示结果排名
$p = ceil($i / 10); //搜索结果第几页
$i_weight = array(1 => 52, 2 => 15, 3 => 10, 4 => 5, 5 => 5, 6 => 4, 7 => 1, 8 => 3, 9 => 2, 0 => 3);
$h_str = preg_replace("/^.*?://(.*?)(#.*)?$/i", "$1$3", $h); //去除url中的协议(例如http)与#信息片段部分
$h_arr = explode("?", $h_str, 2);
$h0_arr = explode("/", $h_arr[0]);
if ($h0_arr[count($h0_arr) - 1] == '')
{
$level_l = count($h0_arr) - 1;
}
else
{
$level_l = count($h0_arr);
}
if (isset($h_arr[1]))
{
if ($h_arr[1] != '')
{
$level_r = count(explode("&", $h_arr[1]));
}
else
{
$level_r = 0;
}
}
else
{
$level_r = 0;
}
$dw = $i_weight[$i % 10] * pow(0.5, ($level_l + $level_r - 1)) * 9 / pow(10, $p);
return number_format($dw, 1);;
}function fetch_baidu($d, $k)
{
$urlw = urlencode(iconv("utf-8","gbk//ignore",$k));
$max_srh_page = 2; //百度搜索结果50条/页,提取2页,也就是只在前100条搜索结果中检查排名,最大值可以设为16
$baidu_ids = array(); //存储百度系列子站点占据的排名位置
$baidu_mus = array(); //存储百度开放平台等优质站点占据的排名位置
$isrank = 0; //$isrank = 1 当前域名下这个关键词获得排名; $isrank = 0 当前域名下这个关键词没有排名
$all_count = 0; //测试变量,以确认匹配规则不会遗漏任何一条搜索结果
$dm_weight = 0; //分析搜索结果页面中顶级、次级、目录、内页的情况,粗略反映一个关键字的竞争激烈程度,非常不准,仅供参考
for ($page_no = 1; $page_no <= $max_srh_page; $page_no++)
{
if ($page_no > 16) break;
$fail_try = 1;
$pn = ($page_no - 1) * 50;
$url = "http://www.baidu.com/s?wd={$urlw}&pn={$pn}&rn=50";
$snoopy = new snoopy;
// $snoopy->proxy_host = "127.0.0.1"; //采集可选代理ip,以免频繁抓百度反被百度咬
// $snoopy->proxy_port = "80"; //proxy代理所用端口
$snoopy->fetch($url);
$contents = iconv("gbk","utf-8//ignore",$snoopy->results);
unset($snoopy);
// echo $contents;
if (!preg_match("/<span>此内容系百度根据您的指令自动搜索的结果/i",$contents,$out))
{
if ($fail_try > 5)
{
continue;
}
else
{
$fail_try++;
$page_no--;
sleep(30);
continue;
}
}
if (!isset($ebaidu))
{
$ebaidu = array('lt' => 0, 'lb' => 0, 'r' => 0); //记录百度推广数量,分为左上、左下、右侧
if (preg_match_all("/<tr><td class="f ec_pp"><a id="awd+"/i", $contents, $out_lt))
{
$ebaidu['lt'] = count($out_lt[0]);
}
if (preg_match_all("/<table id="40d+".*?class="ec_mr15">/i", $contents, $out_lt))
{
$ebaidu['lt'] = count($out_lt[0]);
}
if (preg_match_all("/<table width="65%".*?class="ec_mr15">/i", $contents, $out_lb))
{
$ebaidu['lb'] = count($out_lb[0]);
}
if (preg_match_all("/<div id="bdfsd+" class="ec_pp".*?><a id=dfsd+/i", $contents, $out_r))
{
$ebaidu['r'] = count($out_r[0]);
}
}
if (preg_match_all("/((<table cellpadding="0" cellspacing="0".*?id="(d+)" mu="(.*?)">)|(<table id="(d+)" cellpadding="0" cellspacing="0" mu="(.*?)">))[s|s]*?((<a.*?href=".*?".*?>(.*?)</a>)|(<div id="app_.*?"></div>))/i", $contents, $out_mu))
{
foreach ($out_mu[0] as $om_key => $om_val)
{
$om_id1 = $out_mu[3][$om_key];
$om_href1 = $out_mu[4][$om_key];
$om_id2 = $out_mu[6][$om_key];
$om_href2 = $out_mu[7][$om_key];
$om_title = strip_tags($out_mu[10][$om_key]);
$baidu_mus[] = $om_id1 . $om_id2;
$dm_weight = $dm_weight + get_dm_weight($om_href1 . $om_href2, $om_id1 . $om_id2);
if (preg_match("/://(w*?.)*?baidu.com//i", $om_href1 . $om_href2, $om_domain))
{
$baidu_ids[] = $om_id1 . $om_id2;
}
if (preg_match("/://(w*?.)*?{$d}//i", $om_href1 . $om_href2, $om_domain))
{
echo '<div style="clear:both"></div><span class="s_kw"><a href="http://www.baidu.com/s?wd=' . $urlw . '">' . $k . '</a></span><span class="s_rank">' . $om_id1 . $om_id2 . '</span><span class="s_wt"></span><span class="s_title"><a href="' . $om_href1 . $om_href2 . '">' . $om_title . '</a></span><span class="s_cache"></span>';
$isrank = 1;
}
}
}
if (preg_match_all("/<table cellpadding="0" cellspacing="0" class="result" id="(d+)"><tr><td class=f><h3 class="t">(<font.*?</font>)?<a.*?href="(.*?)" target="_blank">(.*?)</a></h3><font size=-1>.*?<span class="g">.*? ((d{4}-d{1,2}-d{1,2})|(d+小时前)|(d+分钟前)) .*?</span>.*?<br></font></td></tr></table>/i", $contents, $out_all))
{
foreach ($out_all[0] as $o_key => $o_val)
{
$o_id = $out_all[1][$o_key];
$o_href = $out_all[3][$o_key];
$o_title = strip_tags($out_all[4][$o_key]);
$o_cache = $out_all[6][$o_key] . $out_all[7][$o_key] . $out_all[8][$o_key];
$dm_weight = $dm_weight + get_dm_weight($o_href, $o_id);
if (preg_match("/://(w*?.)*?baidu.com//i", $o_href, $o_domain))
{
$baidu_ids[] = $o_id;
}
if (preg_match("/://(w*?.)*?{$d}//i", $o_href, $o_domain))
{
echo '<div style="clear:both"></div><span class="s_kw"><a href="http://www.baidu.com/s?wd=' . $urlw . '">' . $k . '</a></span><span class="s_rank">' . $o_id . '</span><span class="s_wt">' . $dm_weight . '%</span><span class="s_title"><a href="' . $o_href . '">' . $o_title . '</a></span><span class="s_cache">' . $o_cache . '</span>';
$isrank = 1;
}
}
}
//$all_count用来检查上述正则匹配是否匹配到所有搜索结果,特别关注百度系列站点、百度开放平台以及百度应用等有别于普通搜索结果
if (isset($out_mu[0])) $all_count = $all_count + count($out_mu[0]);
if (isset($out_all[0])) $all_count = $all_count + count($out_all[0]);
// echo '<br />总共找到' . $all_count . '个匹配<br />';
if (!preg_match("/<a href="s?wd=.*?>下一页</a>.*?</p>/i",$contents,$out))
{
break;
}
}
if (count($baidu_mus) >= 1)
{
$bmus = implode(",", $baidu_mus);
}
else
{
$bmus = '';
}
if (count($baidu_ids) >= 1)
{
$bids = implode(",", $baidu_ids);
}
else
{
$bids = '';
}
if ($isrank == 1)
{
echo '<span class="s_feng">上' . $ebaidu['lt'] . '下' . $ebaidu['lb'] . '右' . $ebaidu['r'] . '</span><span class="s_baidu">' . $bids . '</span><span class="s_mu">' . $bmus . '</span>';
}
else
{
echo '<div style="clear:both"></div><span class="s_kw"><a href="http://www.baidu.com/s?wd=' . $urlw . '">' . $k . '</a></span><span class="s_rank">0</span><span class="s_wt">' . $dm_weight . '%</span><span class="s_title"></span><span class="s_cache"></span><span class="s_feng">上' . $ebaidu['lt'] . '下' . $ebaidu['lb'] . '右' . $ebaidu['r'] . '</span><span class="s_baidu">' . $bids . '</span><span class="s_mu">' . $bmus . '</span>';
}
unset($ebaidu);
}
//逐个域名与关键字采集百度排名信息并显示
set_include_path(".");
include "snoopy.class.php";
set_time_limit(0);
ob_flush(); flush(); ob_end_clean(); ob_implicit_flush(1);
echo '<div id="kgrid">';
echo '<span class="s_kw">关键字</span><span class="s_rank">排名</span><span class="s_wt">竞争度</span><span class="s_title">网页标题</span><span class="s_cache">百度快照</span><span class="s_feng">百度推广数量</span><span class="s_baidu">百度占位</span><span class="s_mu">百度mu占位</span>';
foreach ($kwlist as $d_ks)
{
$dm = $d_ks['domain'];
echo '<div style="clear:both"></div><span class="s_bar">域名:' . $dm . '</span>';
foreach ($d_ks['kword'] as $k)
{
fetch_baidu($dm, $k);
}
}
echo '</div>';
?>
</div><!--div main end-->
</div><!--div wrap end-->
<?php
tongji();
?>
</body>
</html>
php教程 自动分页类函数
不想重复的写sql代码,就用下面的函数去自动处理了。
$__t_page_moyo_html = '';
/**
*
* 临时代码:分页处理函数
* @param string $sql
*/
function page_moyo($sql = '')
{
global $__t_page_moyo_html;
if ($sql == '')
{
return $__t_page_moyo_html;
}
// config
$max = 12;
$flag = 'page';
// step .1 处理sql语句
$sql_count = preg_replace('/select.*?from/is', 'select count(*) as mcnt from', $sql);
// step .2 获取数据量
$result = dbc()->query($sql_count)->getrow();
$total = $result['mcnt'];
// step .3 判断是否需要分页
if ($total < $max)
{
return $sql;
}
// step .4 获取当前页数
$pn = isset($_get[$flag]) ? (int)$_get[$flag] : 1;
if ($pn <= 0) $pn = 1;
// step .5 重组sql语句
$sql = $sql . ' limit '.($pn-1)*$max.','.$max;
// step .6 组装分页html代码
$url = $_server['request_uri'];
if (preg_match('/'.$flag.'=d+/i', $url))
{
$url = preg_replace('/[&]?'.$flag.'=d+/', '', $url);
}
$pageall = ceil($total/$max);
$pre = '';
if ($pn > 1)
{
$pre = ' / <a href="'.$url.'&'.$flag.'='.($pn-1).'">上一页</a>';
}
$nxt = ' / <a href="'.$url.'&'.$flag.'='.($pn+1).'">下一页</a>';
$html = '<a href="'.$url.'">首页</a>'.$pre.$nxt.' / <a href="'.$url.'&'.$flag.'='.$pageall.'">尾页</a>';
$__t_page_moyo_html = $html;
return $sql;
}
在进行sql查询前用page_moyo处理一下sql语句
$sql = page_moyo($sql);
然后在需要显示分页链接的地方直接调用page_moyo输出
echo page_moyo();
如果要连续进行两次大数据量sql查询的话就要在第一次查询后存储下当时的分页代码,不然下个sql查询就会覆盖掉了
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>php教程 在线切图程序代码
</title>
<style>
/* { -moz-box-sizing:border-box; } */body {
background-color:#aaa;
font-family:tahoma;
font-size:12px;
}
a {
text-decoration: none;
outline:none;
}
a:focus {
-moz-outline:none;
outline:none;
}#window {
background-color:threedface;
position:absolute;
width:850px;
height:500px;
left:10%;
top:10%;border:1px solid;
border-top-color:threedlightshadow;
border-left-color:threedlightshadow;
border-right-color:windowframe;
border-bottom-color:windowframe;z-index:2;
}#workspace {
background-color:#ece9d8; /*threedface*/
overflow:auto;position:absolute;
width:98%;
height:84%;
top:51px;
left:8px;
right:0;
bottom:74px;
z-index:3;border:1px solid;
border-top-color:threeddarkshadow;
border-left-color:threeddarkshadow;
border-right-color:threedhighlight;
border-bottom-color:threedhighlight;
}#myimg {
display:none;
position:absolute;
margin:3px;
}
#canvas, #canvastemp {
display:none;
position:absolute;
margin:3px;
background-color:transparent;
border:1px solid #666666;
/* background-image:url(back.gif); */
}
#shapes{
position:absolute;
margin:3px;
}#titlebar, #menubar, #statusbar, #resize {
background-color:threedface;
z-index:10;
position:absolute;
}#titlebar {
left:2px;
top:2px;
height:22px;
width:99.4%;
overflow:hidden;}
#gradient {
width:100%;
}
#menubar {
left:0px;
top:27px;
height:20px;
width:100%;
list-style:none;
margin:0;padding:0;
z-index:10;
border-bottom:1px solid threedshadow;
}#menubar li {
border:0px;
margin:0;
margin-top:1px;
font:menu;
float:left;
padding:1px;
padding-left:0.4em; padding-right:0.4em;
cursor:default;
}#statusbar {
z-index:6;
left:8px;
bottom:0;
height:26px;
width:98%;
border-top:1px solid threedhighlight;
padding-top:2px;
}#resize {
z-index:100;
bottom:0; right:0;
width:15px; height:15px;
background:transparent url('../resize.gif') 3px 3px no-repeat;
cursor:nw-resize;
}#titlebar canvas {
position:absolute;
width:100%;
}
#titlebar h1 {
background:transparent url('../cut.gif') 1px 2px no-repeat;
position:absolute;
color:captiontext;
font-size:12px;
margin:0;padding:0;
padding-left:20px;
padding-top:2px;
cursor:default;
}
#titlebar h2 {
position:absolute;
color:yellow;
font-size:12px;
margin:0;padding:0;
right:8px;
padding-top:2px;
cursor:default;
}
#statusbar2 {
margin-left:0px;
}#statusbar2 > div {
float:left;
}#statusbar2 #status { float:left; width:57%;}
#statusbar2 #xy { float:left; width:20%;}
#statusbar2 #txy { float:left; width:20%;}#status div, #xy div, #txy div {
padding:3px;
border:1px solid;
border-top-color:threedshadow;
border-left-color:threedshadow;
border-right-color:threedhighlight;
border-bottom-color:threedhighlight;
height:1.3em;
*height:1.7em;
line-height:1.3em;
overflow:hidden;
}
</style>
<script>
var mode = 1;
var inout = toubai = 0;
var img, imgurl = '', imgdata = '';
var p = '';
var xydir = 15;
var startangle=0, endangle=(math.pi/180)*270;
var m;
var win, wsp, canvas, c, canvastemp, ctemp, shapes;
var w,h,f;
var isshift = 0;
var shape = 0;
var theobject = null;
var dx, dy, dw, dh;
var des = '';
var iface = { dragging:false, resizing:false, status:null, xy:null, txy:null }
var anyt = 1;var isie = /msie/i.test(navigator.useragent);
var isff = /firefox/i.test(navigator.useragent);window.onload = function()
{
win = document.getelementbyid('window');
wsp = document.getelementbyid('workspace');img = document.getelementbyid('myimg');
canvas = document.getelementbyid('canvas');
canvastemp = document.getelementbyid("canvastemp");
shapes = document.getelementbyid('shapes');
rects = document.getelementbyid('rect');
win.style.left = document.body.clientwidth/2-425+'px';
if (canvas.getcontext)
{
c = canvas.getcontext("2d");
c.linewidth = 1;
c.strokestyle = '#f00';
c.fillstyle = "rgba(255,255,255,0.3)";
c.strokefill = 1;ctemp = canvastemp.getcontext("2d");
ctemp.linewidth = 1;
ctemp.strokestyle = '#f00';
ctemp.fillstyle = "rgba(255,255,255,0.3)";
ctemp.strokefill = 1;
var gradientcanvas = document.getelementbyid('gradient');
if (gradientcanvas.getcontext)
{
var g = gradientcanvas.getcontext('2d');
var grad = g.createlineargradient(0, 0, 1200, 22);
grad.addcolorstop(0, '#036');
grad.addcolorstop(1, '#acf');
g.fillstyle = grad;
g.fillrect(0, 0, 1200, 22);
}
iface.status = document.getelementbyid('status').firstchild;
iface.xy = document.getelementbyid('xy').firstchild;
iface.txy = document.getelementbyid('txy').firstchild;
document.onmouseup = window.onmouseup = bodyup;
document.onmousemove = window.onmousemove = bodymove;
document.onkeydown = window.onkeydown = keydown;
document.onkeyup = window.onkeyup = keyup;
img.onmousedown = canvas.onmousedown = canvastemp.onmousedown = shapes.onmousedown = c_down;
img.onmousemove = canvas.onmousemove = canvastemp.onmousemove = shapes.onmousemove = c_move;
img.onmouseup = canvas.onmouseup = canvastemp.onmouseup = shapes.onmouseup = c_up;
img.onmouseo教程ut = canvas.onmouseout = canvastemp.onmouseout = c_out;
}
else //不支持canvas属性
{
alert('不支持canvas');
}}
function openimg()
{
var form = document.upimg;var file = form.ifile.value;
var pos = file.lastindexof('.');
var ext = file.substring(pos + 1).tolowercase();
if (ext != 'jpg' && ext != 'gif' && ext != 'bmp' && ext != 'png')
{
alert('错误:上传图片必须是 jpg/gif/bmp/png 格式!');
return;
}
form.submit.click();
document.getelementbyid('upimg').style.display = 'none';
}function upimg(url, size, ww, hh, ff)
{
shape = 0;
des = '大小:'+size+' 字节 帧数:'+ff+' 帧 宽度:'+ww+' 像素 高度:'+hh+' 像素';
iface.status.innerhtml=des;
imgurl = url;
imgdata = 'imgurl='+imgurl+';';
if (ww>800) {w = 800; h = hh/(ww/800);}
else {w = ww; h= hh;}
f = ff;
//img.src = imgurl;
document.getelementbyid('myimg').style.display = 'block';
document.getelementbyid('myimg').src = imgurl;
canvas.style.display='block';
canvastemp.style.display='block';
canvas.width = canvastemp.width = w;
canvas.height = canvastemp.height = h;
canvas.style.width = canvastemp.style.width = w+'px';
canvas.style.height = canvastemp.style.height = h+'px';
c.clearrect(0, 0, canvas.width, canvas.height);
ctemp.clearrect(0, 0, canvastemp.width, canvastemp.height);
c.strokestyle = '#f00';
c.fillstyle = "rgba(255,255,255,0.3)";
ctemp.strokestyle = '#f00';
ctemp.fillstyle = "rgba(255,255,255,0.3)";
}function init(t)
{
if (imgurl == '') {alert('请先上传图片!');return;}
else alert("当前版本是演示版!");
}
function reset()
{
if (imgurl == '') {alert('请先上传图片!');return;}
else alert("当前版本是演示版!");
}
function clip()
{
if (imgurl == '') {alert('请先上传图片!');return;}
else alert("当前版本是演示版!");
}function hover(o)
{
o.style.border = "1px solid";
o.style.bordercolor = "threedhighlight threeddarkshadow threeddarkshadow threedhighlight";
}
function hoverout(o)
{
o.style.border = "0px solid transparent";
}function help()
{
document.getelementbyid('help').style.display='block';
}
function about()
{
document.getelementbyid('about').style.display='block';
}
function wrong(str)
{
alert(str);
}
</script>
<!--[if ie]>
<script type="text/网页特效" src="js/excanvas.js"></script>
<![endif]-->
</head><body id="body">
<form name="build" enctype="multipart/form-data"><input type="hidden" name="imgdata"><input type="hidden" name="region"><input type="hidden" name="back"><input type=submit name=submit style="position:absolute;filter:alpha(opacity=0);-moz-opacity:0;opacity:0;");></form><div id="window">
<div id="titlebar" onmousedown="windowdrag(event)" oncontextmenu="return false"><canvas id="gradient" height="22"></canvas><h1 style="margin-top:2px;">图片裁剪工具</h1><h2 style="margin-top:1px;"><a href="javascript:help();" hidefocus="true"><font color=yellow>操作说明</font></a> <a href="javascript:about();" hidefocus="true"><font color=yellow>关于我们</font></a></h2>
</div>
<ul id="menubar" oncontextmenu="return false">
<li onmouseover="hover(this)" onmouseout="hoverout(this)" onclick="document.getelementbyid('help').style.display='none';document.getelementbyid('about').style.display='none';document.getelementbyid('set').style.display='none';document.getelementbyid('upimg').style.display='block';"> 上传图片(<u>u</u>)</li>
<li onmouseover="hover(this)" onmouseout="hoverout(this)" onclick="init(1);">矩形裁剪(<u>r</u>)</li>
<li onmouseover="hover(this)" onmouseout="hoverout(this)" onclick="init(2)">圆形裁剪(<u>o</u>)</li>
<li onmouseover="hover(this)" onmouseout="hoverout(this)" onclick="init(3)">圆角矩形裁剪(<u>c</u>)</li>
<li onmouseover="hover(this)" onmouseout="hoverout(this)" onclick="init(4)">圆弧裁剪(<u>a</u>)</li>
<li onmouseover="hover(this)" onmouseout="hoverout(this)" onclick="init(5)">多边形裁剪</li>
<li style="top:0px;margin-left:-3px;padding-left:0px;margin-top:-2px;padding-top:0px;padding-bottom:0px;"><input type="radio" name="any" id="line" hidefocus disabled checked>直边<input type="radio" name="any" id="curve" hidefocus disabled>曲边</li>
<li onmouseover="hover(this)" onmouseout="hoverout(this)" onclick="init(6)">任意图形裁剪(<u>m</u>)</li>
<li style="margin-top:0px;margin-right:7px;*margin-right:5px;float:right;padding-top:1px;*padding-top:2px;padding-bottom:1px;*padding-bottom:0px;border:1px solid threeddarkshadow;color:red" onclick="clip()">裁剪</li>
<li style="margin-top:0px;margin-right:7px;*margin-right:5px;float:right;padding-top:1px;*padding-top:2px;padding-bottom:1px;*padding-bottom:0px;border:1px solid threeddarkshadow;color:red" onclick="reset()">重置</li>
<li style="margin-top:0px;margin-right:7px;*margin-right:5px;float:right;padding-top:1px;*padding-top:2px;padding-bottom:1px;*padding-bottom:0px;border:1px solid threeddarkshadow;color:red" onclick="document.getelementbyid('set').style.display='block'">设置</li>
</ul>
<div id="workspace" oncontextmenu="return false">
<img id="myimg">
<canvas id="canvas" oncontextmenu="return false"></canvas>
<canvas id="canvastemp" oncontextmenu="return false"></canvas>
<div id="shapes">
<table class=resizeme id=rect style="position:absolute;z-index:100;border:0px dotted #ff0000;width:100;height:100;display:none;" cellspacing="0" cellpadding="0"><tr><td></td></tr></table>
</div>
</div><div id="statusbar" oncontextmenu="return false"><div id="statusbar2">
<div id="status"><div> </div></div>
<div id="xy"><div> </div></div>
<div id="txy"><div> </div></div>
</div></div>
<div id="resize" onmousedown="windowresize(event, this)" oncontextmenu="return false"></div><form id="upimg" name="upimg" action="upload.php" method="post" enctype="multipart/form-data" target="_frame" style="position:absolute;background-color:#036;left:50%;top:50%;margin-left:-163px;*margin-left:-175px;margin-top:-80px;width:325px;*width:350px;padding-top:3px;padding-left:3px;padding-bottom:3px;padding-right:3px;z-index:12;display:none">
<div style="background-color:#036;padding-top:1px;padding-left:2px;color:captiontext;font-size:12px;height:20px"><b> 上传图片</b></div>
<div style="background-color:threedface;padding-top:6px;padding-bottom:6px;padding-left:10px;"><input size="24" type="file" name="ifile" onchange="openimg();" style="height:22px"> <input type="button" value=" 取 消 " style="height:22px" onclick="document.getelementbyid('upimg').style.display='none'"><input type=submit name=submit style="position:absolute;filter:alpha(opacity=0);-moz-opacity:0;opacity:0;"></div>
</form>
<form id="set" name="set" style="position:absolute;background-color:#036;left:50%;top:50%;margin-left:-125px;margin-top:-80px;width:250px;padding-top:3px;padding-left:3px;padding-bottom:3px;padding-right:3px;z-index:12;display:none">
<div style="background-color:#036;padding-top:1px;padding-left:2px;color:captiontext;font-size:12px;height:20px"><b> 设置</b></div>
<div><div style="background-color:threedface;padding-top:6px;padding-bottom:6px;padding-left:24px">裁剪方向:<input type="radio" name=inout id=isin hidefocus checked>裁剪内部 <input type="radio" name=inout id=isout hidefocus>裁剪外部<p style="margin-top:3px;margin-bottom:3px">背景颜色:<input type="radio" name=toubai id=istou value=0 hidefocus checked>透明背景 <input type="radio" name=toubai id=isbai value=1 hidefocus>白色背景</div><div style="background-color:threedface;padding-bottom:8px;"><center><input type="button" value=" 确 定 " style="height:22px" onclick="setting()"> <input type="button" value=" 取 消 " style="height:22px" onclick="document.getelementbyid('set').style.display='none'"></center></div></div>
</form>
<div id="help" style="position:absolute;background-color:#036;left:50%;top:50%;margin-left:-210px;margin-top:-170px;width:420px;padding-top:3px;padding-left:3px;padding-bottom:3px;padding-right:3px;z-index:12;display:block">
<div style="background-color:#036;padding-top:1px;padding-left:2px;color:captiontext;font-size:12px;height:20px"><b> 操作说明</b></div>
<div><div style="background-color:threedface;padding-top:6px;padding-bottom:6px;padding-left:10px;padding-right:10px"><center><font color=red>【鼠标操作说明】</font></center><p style="margin-top:6px;margin-bottom:6px">[1] 鼠标拖动裁剪框可移动裁剪区域的位置,此操作适用于矩形裁剪,圆形裁剪,圆角矩形裁剪,圆弧裁剪。<p style="margin-top:4px;margin-bottom:4px">[2] 鼠标拉拽裁剪框边框可调整裁剪区域的大小,此操作适用于矩形裁剪,圆形裁剪,圆角矩形裁剪,圆弧裁剪。<p style="margin-top:8px;margin-bottom:8px"><center><font color=red>【键盘操作说明】</font></center><p style="margin-top:6px;margin-bottom:6px">[3] 按←↑↓→键可精确移动裁剪区域的位置,此操作适用于矩形裁剪,圆形裁剪,圆角矩形裁剪,圆弧裁剪。<p style="margin-top:4px;margin-bottom:4px">[4] 按jklm键可精确调整裁剪区域的大小,此操作适用于矩形裁剪,圆形裁剪,圆角矩形裁剪,圆弧裁剪。<p style="margin-top:4px;margin-bottom:4px">[5] 按a键减小圆角矩形的圆角角度,按d键增大圆角矩形的圆角角度,此操作适用于圆角矩形裁剪。<p style="margin-top:4px;margin-bottom:4px">[6] 按awsd键可调整圆弧的弧度,此操作适用于圆弧裁剪。<p style="margin-top:8px;margin-bottom:8px"><center><font color=red>【shift操作说明】</font></center><p style="margin-top:6px;margin-bottom:6px">[7] 拉拽鼠标的同时按shift键可按宽与高1:1的比例调整裁剪区域的大小,此操作适用于矩形裁剪,圆形裁剪,圆角矩形裁剪。</div><div style="background-color:threedface;padding-bottom:8px;"><center><input type="button" value=" 关 闭 " style="height:22px" onclick="document.getelementbyid('help').style.display='none'"></center></div></div>
</div>
<div id="about" style="position:absolute;background-color:#036;left:50%;top:50%;margin-left:-190px;margin-top:-120px;width:380px;padding-top:3px;padding-left:3px;padding-bottom:3px;padding-right:3px;z-index:12;display:none">
<div style="background-color:#036;padding-top:1px;padding-left:2px;color:captiontext;font-size:12px;height:20px"><b> 关于我们</b></div>
<div><div style="background-color:threedface;padding-top:8px;padding-bottom:6px;padding-left:10px"><center><font color=red>【本站宗旨】</font></center><p style="margin-top:6px;margin-bottom:6px">● 本站旨在为广大网民提供最专业最全面的图片裁剪服务.<p style="margin-top:8px;margin-bottom:8px"><center><font color=red>【站点说明】</font></center><p style="margin-top:6px;margin-bottom:6px">● 本站提供以下服务:图片裁剪,照片裁剪,矩形裁剪,圆形裁剪,弧形裁剪,多边形裁剪,任意图形裁剪,动态图片裁剪.<p style="margin-top:8px;margin-bottom:8px"><center><font color=red>【联系我们】</font></center><p style="margin-top:6px;margin-bottom:6px">● 对本站如有疑问之处请与我们联系:service@caijian.cc.</div><div style="background-color:threedface;padding-bottom:8px;"><center><input type="button" value=" 关 闭 " style="height:22px" onclick="document.getelementbyid('about').style.display='none'"></center></div></div>
</div>
<div style="display:none;">
<iframe id="_frame" name="_frame"></iframe>
</div>
</div>
</body>
</html>upload.php文件
<?php
if (stripos($_server[ "http_host"], 'caijian.cc') === false) exit(0);
if ((($_files["ifile"]["type"] == "image/gif")
|| ($_files["ifile"]["type"] == "image/jpeg")
|| ($_files["ifile"]["type"] == "image/pjpeg")
|| ($_files["ifile"]["type"] == "image/bmp")
|| ($_files["ifile"]["type"] == "image/png"))
&& ($_files["ifile"]["size"] < 3000000))
{
if ($_files["ifile"]["error"] > 0)
{
echo "<script language='javascript'>" ;
echo "parent.wrong('上传图片出错,请重新上传!');";
echo "</script>";
}
else
{
$filename = "upload/".date("ymdhis",time()).rand(100,999).substr($_files["ifile"]["name"],strrpos($_files["ifile"]["name"],'.'));
move_uploaded_file($_files["ifile"]["tmp_name"], $filename);
$magick_wand = newmagickwand();
magickreadimage($magick_wand, $filename);
$w = magickgetimagewidth($magick_wand);
$h = magickgetimageheight($magick_wand);
$f = magickgetnumberimages($magick_wand);
echo "<script language='javascript'>" ;
echo "parent.upimg('".$filename."',".$_files["ifile"]["size"].", $w, $h, $f);";
echo "</script>";
}
}
else
{
echo "<script language='javascript'>" ;
echo "parent.wrong('上传照片尺寸不得大于3m!');";
echo "</script>";
}
?>
源码下载地址
http://down.111cn.net/php/2011/0311/22879.html
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>php教程 文件图片上传类程序</title>
</head><body>
<form enctype="multipart/form-data" action="upx.php" method="post">
<input name="swfile" type="file">
<input type="submit" value="上传">
</form>
</body>
</html>
upx.php文件
<?php
//上传操作
require_once './libs/uploadx.php';
$upx = new uploadx();
$upx->uploadx_form = 'swfile';
$upx->uploadx_save = "upload";
$upx->uploadx_size = "1024";
$upx->uploadx_name = time();
$upx->file();
print_r($upx->file);?>
uploadx.php类文件
<?php
/*使用方法:
html表单页
-------------------------------------------------------------------------
<form enctype="multipart/form-data" action="upload.php" method="post">
<input name="swfile" type="file">
<input type="submit" value="上传">
</form>
-------------------------------------------------------------------------
upload.php处理页
-------------------------------------------------------------------------
<?php
require_once './uploadx.php';
$upx = new uploadx();
$upx->uploadx_form = 'swfile'; //表单控件名称(表单上传控件的名称<input name="swfile" type="file" />)
$upx->uploadx_save = "temp"; //保存文件目录(上传文件保存目录可以是相对路径也可以是绝对路径)
$upx->uploadx_type = 'jpg|gif|png|swf'; //允许上传类型(根据后缀限制上传类型,每个后缀用"|"隔开)
$upx->uploadx_size = "1024"; //允许上传大小(单位是kb。例:1024=1024kb)
$upx->uploadx_name = time(); //上传后文件名(可自定义。例:date("y-m-d",time()))if($upx->file()){
echo "上传成功<br />";
echo "名称->".$upx->file['name']."<br />";
echo "路径->".$upx->file['path']."<br />";
echo "大小->".$upx->file['size']."<br />";
echo "类型->".$upx->file['type']."<br />";
echo "时间->".$upx->file['time']."<br />";
echo "结果->".$upx->file['info']."<br />";
}else{
echo $upx->file['info'];
}
-------------------------------------------------------------------------
*/
class uploadx {
public $uploadx_form; //表单控件名称
public $uploadx_save; //保存文件目录
public $uploadx_type; //允许上传类型
public $uploadx_size; //允许上传大小
public $uploadx_name; //上传后文件名
function __construct(){//初始化函数
$this->uploadx_form = 'attach';
$this->uploadx_save = 'temp';
$this->uploadx_type = 'jpg|gif|png|swf|flv|rar|7z|zip|doc|docx|ppt|pptx|xls|xlsx|txt|pdf|wav|mp3|wma|rm|rmvb|wmv';
$this->uploadx_size = '1024';
$this->uploadx_info = false;
}
function mkdirs($path , $mode = 0777){
$rootdir = '';
if(substr($path,0,1)=='/') $rootdir = $_server['document_root'];
$path = $rootdir . $path;
if(!is_dir($path)){
$this->mkdirs(dirname($path),$mode);
mkdir($path,$mode);
}
return true;
}
function file(){
if(!isset($_files[$this->uploadx_form])){
$this->file = array('file'=>false,'info' => '上传错误!请检查表单上传控件名称['.$this->uploadx_form.']是否正确!');
return false;
}
switch($_files[$this->uploadx_form]['error']){
case 1:
$this->file = array('file'=>false,'info' => '指定上传的文件大小超出服务器限制!');
return false;
break;
case 2:
$this->file = array('file'=>false,'info' => '指定上传的文件大小超出表单限制!');
return false;
break;
case 3:
$this->file = array('file'=>false,'info' => '只有部份文件被上传,文件不完整!');
return false;
break;
case 4:
$this->file = array('file'=>false,'info' => '您没有选择上传任何文件!');
return false;
}
$postfix = pathinfo($_files[$this->uploadx_form]['name'], pathinfo_extension);
if(stripos($this->uploadx_type,$postfix)===false){
$this->file = array('file'=>false,'info' => '指定上传的文件类型超出限制,允许上传文件类型:'.$this->uploadx_type);
return false;
}
if(round($_files[$this->uploadx_form]['size']/1024)>$this->uploadx_size){
$this->file = array('file'=>false,'info' => '指定上传的文件超出大小限制,文件上传限制范围:'.$this->uploadx_size.'kb');
return false;
}
if($this->mkdirs($this->uploadx_save)){
$this->uploadx_name = isset($this->uploadx_name) ? $this->uploadx_name.'.'.$postfix : $_files[$this->uploadx_form]['name'];
if(!@move_uploaded_file($_files[$this->uploadx_form]['tmp_name'],$this->uploadx_save.'/'.$this->uploadx_name)){
$this->file = array('file'=>false,'info' => '上传文件保存过程中出现错误,请检查路径或目录权限.');
return false;
}
}else{
$this->file = array('file'=>false,'info' => '服务器目录不存在,自动创建目录失败,请检查是否有权限!');
return false;
}
@chmod($this->uploadx_save.'/'.$this->uploadx_name,0777);
$this->file = array(
'file' => true,
'name' => $this->uploadx_name,
'path' => $this->uploadx_save.'/'.$this->uploadx_name,
'size' => $_files[$this->uploadx_form]['size'],
'type' => $postfix,
'time' => time(),
'info' => '上传成功!'
);
return true;
}
}
相关文章
- 今天小编在这里就来给Painter的这一款软件的使用者们来说一说绘制红衣喝酒男水粉画效果的教程,各位想知道具体绘制步骤的使用者,那么下面就快来跟着小编一起看一看教程...2016-09-14
- 今天小编在这里就来给photoshop的这一款软件的使用者们来说说利用各种素材合成闪电侠效果的制作教程,各位想知道具体制作步骤的使用者们,那么下面就快来跟着小编一起看...2016-09-14
- 今天小编在这里就来给美图秀秀的这一款软件的使用者们来说下把普通照片快速转换成卡通效果的教程,各位想知道具体制作步骤的使用者们,那么下面就快阿里跟着小编一起看一...2016-09-14
- strstr() 函数搜索一个字符串在另一个字符串中的第一次出现。该函数返回字符串的其余部分(从匹配点)。如果未找到所搜索的字符串,则返回 false。语法:strstr(string,search)参数string,必需。规定被搜索的字符串。 参数sea...2013-10-04
- 本文实例讲述了JS实现双击屏幕滚动效果代码。分享给大家供大家参考,具体如下:这里演示双击滚屏效果代码的实现方法,不知道有觉得有用处的没,现在网上还有很多还在用这个特效的呢,代码分享给大家吧。运行效果截图如下:在线演...2015-10-30
- 今天小编在这里就来给photoshop的这一款软件的使用者们来说说调出时尚个性青色人像照片效果的调色教程,各位想知道到底该怎么调色的,那么下面就快来跟着小编一起看一看...2016-09-14
- ps软件是现在很多人比较喜欢的,有着非常不错的使用效果,这次文章就给大家介绍下ps怎么制作图片阴影效果,还不知道制作方法的赶紧来看看。 ps图片阴影效果怎么做方法/...2017-07-06
- ps软件是现在很多人比较喜欢使用的,有着非常不错的功能。这次文章就给大家介绍下ps立体倒影效果制作方法,还不知道怎么制作的赶紧来看看。 最终效果  1...2017-07-06
- ps软件是现在非常受大家喜欢的一款软件,有着非常不错的制作效果。下面文章就给大家介绍下ps制作立体文字效果教程,感兴趣的一起来看看。 ps文字立体效果怎么做最终...2017-07-06
- 本文章分享一篇关于Photoshop打造科幻片中的人物粒子化消失效果,教程重点是画笔的应用,人物身上产生的碎块,颗粒等都是用自定或下载的笔刷来完成,制作之前最好先下载一些...2016-09-14
- 这篇文章主要介绍了jQuery实现的文字hover颜色渐变效果,以完整实例形式分析了jQuery实现文字颜色渐变效果的相关技巧,涉及jQuery插件jquery-ui-1.8.16.custom.min.js的使用,需要的朋友可以参考下...2016-02-23
- 今天小编在这里给painter的这一款软件的使用者们带来的是绘制水彩油画双重效果向日葵插画的教程,各位想知道具体绘制方法的使用者,那么下面就快来跟着小编一起看一看吧...2016-09-14
- 今天小编在这里就来给Painter的这一款软件的使用者们来说一下绘制卡通小丑头像效果的教程,各位想知道具体制作步骤的使用者,那么下面就快来跟着小编一起看一看制作步骤...2016-09-14
- 本文主要讲述了利用Python网络爬虫对指定京东商城中指定商品下的用户评论进行爬取,对数据预处理操作后进行文本情感分析,感兴趣的朋友可以了解下...2021-05-28
- ps软件是现在很多人比较喜欢的,通过ps软件可以制作很不错的图片效果。这次文章就给大家介绍下使用ps怎么制作任务影子,具体制作方法下面一起来看看。 ps人物影子效...2017-07-06
- 背景固定效果在许多的网站都能看到,今天我们一起来看一个关于CSS制作的页面背景固定和滚动效果,应用非常的好用希望对各位带来帮助。 如何创建一个不需要Javascript...2016-09-14
- 这篇文章主要介绍了JavaScript图片旋转效果实现方法详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-06-29
- 今天带大家爬取携程评论练练手,文中有非常详细的代码示例,对正在学习python的小伙伴们很有帮助,需要的朋友可以参考下...2021-06-02
springboot +redis 实现点赞、浏览、收藏、评论等数量的增减操作
这篇文章主要介绍了springboot +redis 实现点赞、浏览、收藏、评论等数量的增减操作,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-01-15- 本文实例讲述了JS实现双击屏幕滚动效果代码。分享给大家供大家参考,具体如下:这里演示双击滚屏效果代码的实现方法,不知道有觉得有用处的没,现在网上还有很多还在用这个特效的呢,代码分享给大家吧。运行效果截图如下:在线演...2015-10-30