投票系统防刷代码

投票系统防刷代码

$value =$this->host;     
   if(empty($_COOKIE["cook"])){
     setcookie("cook", $value, time()+1800, "/"); 
     $v_host = $this->host;   
     $v_ip = $this->get_real_ip();     
     $v_date =date("Y-m-d");   
     $v_array=explode("-",$v_date);   
     $v_mad =$v_array[1].$v_array[2];   
     $v_sql ="Select * from su_votes where v_domain=$v_host and v_ip=$v_ip and v_mad=$v_mad";
     $r  =mysql_query($v_sql) or die("Error system busy.....plase wait!");
     $rs  =mysql_fetch_array($r);
     if(mysql_num_rows($r)){www.111cn.cn
       $qq  =mysql_query("Select * from des where v_domain=$v_host and v_ip=$v_ip and v_votes<=7  and v_mad=$v_mad") or die(aa);
       if(mysql_num_rows($qq)){
        mysql_query("update f set visited=visited+1 where id=$this->u_id");
        mysql_query("update g set v_votes=v_votes+1 where v_domain=$v_host and v_ip=$v_ip and v_votes<=7  and v_mad=$v_mad");
       } www.111cn.cn
     }else{ 
       mysql_query("insert into su_votes(v_domain,v_ip,v_date,v_votes,v_today,v_mad)value($v_host,$v_ip,$v_date,0,1,$v_mad)");
       mysql_query("update g set visited=visited+1 where id=$this->u_id");
     }   
   } www.111cn.cn
  */
  @mysql_query("update g set visited=visited+1 where id=$this->u_id");
 }

阅读全文

php 世纪万年历


<?
//世纪万年历
#这是唯一的设置-请输入php文件的位置
$file=$_SERVER[PHP_SELF];
//农历每月的天数
$everymonth=array(
0=>array(8,0,0,0,0,0,0,0,0,0,0,0,29,30,7,1),
1=>array(0,29,30,29,29,30,29,30,29,30,30,30,29,0,8,2),
2=>array(0,30,29,30,29,29,30,29,30,29,30,30,30,0,9,3),
3=>array(5,29,30,29,30,29,29,30,29,29,30,30,29,30,10,4),
4=>array(0,30,30,29,30,29,29,30,29,29,30,30,29,0,1,5),
5=>array(0,30,30,29,30,30,29,29,30,29,30,29,30,0,2,6),
6=>array(4,29,30,30,29,30,29,30,29,30,29,30,29,30,3,7),
7=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,4,8),
8=>array(0,30,29,29,30,30,29,30,29,30,30,29,30,0,5,9),
9=>array(2,29,30,29,29,30,29,30,29,30,30,30,29,30,6,10),
10=>array(0,29,30,29,29,30,29,30,29,30,30,30,29,0,7,11),
11=>array(6,30,29,30,29,29,30,29,29,30,30,29,30,30,8,12),
12=>array(0,30,29,30,29,29,30,29,29,30,30,29,30,0,9,1),
13=>array(0,30,30,29,30,29,29,30,29,29,30,29,30,0,10,2),
14=>array(5,30,30,29,30,29,30,29,30,29,30,29,29,30,1,3),
15=>array(0,30,29,30,30,29,30,29,30,29,30,29,30,0,2,4),
16=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,3,5),
17=>array(2,30,29,29,30,29,30,30,29,30,30,29,30,29,4,6),
18=>array(0,30,29,29,30,29,30,29,30,30,29,30,30,0,5,7),
19=>array(7,29,30,29,29,30,29,29,30,30,29,30,30,30,6,8),
20=>array(0,29,30,29,29,30,29,29,30,30,29,30,30,0,7,9),
21=>array(0,30,29,30,29,29,30,29,29,30,29,30,30,0,8,10),
22=>array(5,30,29,30,30,29,29,30,29,29,30,29,30,30,9,11),
23=>array(0,29,30,30,29,30,29,30,29,29,30,29,30,0,10,12),
24=>array(0,29,30,30,29,30,30,29,30,29,30,29,29,0,1,1),
25=>array(4,30,29,30,29,30,30,29,30,30,29,30,29,30,2,2),
26=>array(0,29,29,30,29,30,29,30,30,29,30,30,29,0,3,3),
27=>array(0,30,29,29,30,29,30,29,30,29,30,30,30,0,4,4),
28=>array(2,29,30,29,29,30,29,29,30,29,30,30,30,30,5,5),
29=>array(0,29,30,29,29,30,29,29,30,29,30,30,30,0,6,6),
30=>array(6,29,30,30,29,29,30,29,29,30,29,30,30,29,7,7),
31=>array(0,30,30,29,30,29,30,29,29,30,29,30,29,0,8,8),
32=>array(0,30,30,30,29,30,29,30,29,29,30,29,30,0,9,9),
33=>array(5,29,30,30,29,30,30,29,30,29,30,29,29,30,10,10),
34=>array(0,29,30,29,30,30,29,30,29,30,30,29,30,0,1,11),
35=>array(0,29,29,30,29,30,29,30,30,29,30,30,29,0,2,12),
36=>array(3,30,29,29,30,29,29,30,30,29,30,30,30,29,3,1),
37=>array(0,30,29,29,30,29,29,30,29,30,30,30,29,0,4,2),
38=>array(7,30,30,29,29,30,29,29,30,29,30,30,29,30,5,3),
39=>array(0,30,30,29,29,30,29,29,30,29,30,29,30,0,6,4),
40=>array(0,30,30,29,30,29,30,29,29,30,29,30,29,0,7,5),
41=>array(6,30,30,29,30,30,29,30,29,29,30,29,30,29,8,6),
42=>array(0,30,29,30,30,29,30,29,30,29,30,29,30,0,9,7),
43=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,10,8),
44=>array(4,30,29,30,29,30,29,30,29,30,30,29,30,30,1,9),
45=>array(0,29,29,30,29,29,30,29,30,30,30,29,30,0,2,10),
46=>array(0,30,29,29,30,29,29,30,29,30,30,29,30,0,3,11),
47=>array(2,30,30,29,29,30,29,29,30,29,30,29,30,30,4,12),
48=>array(0,30,29,30,29,30,29,29,30,29,30,29,30,0,5,1),
49=>array(7,30,29,30,30,29,30,29,29,30,29,30,29,30,6,2),
50=>array(0,29,30,30,29,30,30,29,29,30,29,30,29,0,7,3),
51=>array(0,30,29,30,30,29,30,29,30,29,30,29,30,0,8,4),
52=>array(5,29,30,29,30,29,30,29,30,30,29,30,29,30,9,5),
53=>array(0,29,30,29,29,30,30,29,30,30,29,30,29,0,10,6),
54=>array(0,30,29,30,29,29,30,29,30,30,29,30,30,0,1,7),
55=>array(3,29,30,29,30,29,29,30,29,30,29,30,30,30,2,8),
56=>array(0,29,30,29,30,29,29,30,29,30,29,30,30,0,3,9),
57=>array(8,30,29,30,29,30,29,29,30,29,30,29,30,29,4,10),
58=>array(0,30,30,30,29,30,29,29,30,29,30,29,30,0,5,11),
59=>array(0,29,30,30,29,30,29,30,29,30,29,30,29,0,6,12),
60=>array(6,30,29,30,29,30,30,29,30,29,30,29,30,29,7,1),
61=>array(0,30,29,30,29,30,29,30,30,29,30,29,30,0,8,2),
62=>array(0,29,30,29,29,30,29,30,30,29,30,30,29,0,9,3),
63=>array(4,30,29,30,29,29,30,29,30,29,30,30,30,29,10,4),
64=>array(0,30,29,30,29,29,30,29,30,29,30,30,30,0,1,5),
65=>array(0,29,30,29,30,29,29,30,29,29,30,30,29,0,2,6),
66=>array(3,30,30,30,29,30,29,29,30,29,29,30,30,29,3,7),
67=>array(0,30,30,29,30,30,29,29,30,29,30,29,30,0,4,8),
68=>array(7,29,30,29,30,30,29,30,29,30,29,30,29,30,5,9),
69=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,6,10),
70=>array(0,30,29,29,30,29,30,30,29,30,30,29,30,0,7,11),
71=>array(5,29,30,29,29,30,29,30,29,30,30,30,29,30,8,12),
72=>array(0,29,30,29,29,30,29,30,29,30,30,29,30,0,9,1),
73=>array(0,30,29,30,29,29,30,29,29,30,30,29,30,0,10,2),
74=>array(4,30,30,29,30,29,29,30,29,29,30,30,29,30,1,3),
75=>array(0,30,30,29,30,29,29,30,29,29,30,29,30,0,2,4),
76=>array(8,30,30,29,30,29,30,29,30,29,29,30,29,30,3,5),
77=>array(0,30,29,30,30,29,30,29,30,29,30,29,29,0,4,6),
78=>array(0,30,29,30,30,29,30,30,29,30,29,30,29,0,5,7),
79=>array(6,30,29,29,30,29,30,30,29,30,30,29,30,29,6,8),
80=>array(0,30,29,29,30,29,30,29,30,30,29,30,30,0,7,9),
81=>array(0,29,30,29,29,30,29,29,30,30,29,30,30,0,8,10),
82=>array(4,30,29,30,29,29,30,29,29,30,29,30,30,30,9,11),
83=>array(0,30,29,30,29,29,30,29,29,30,29,30,30,0,10,12),
84=>array(10,30,29,30,30,29,29,30,29,29,30,29,30,30,1,1),
85=>array(0,29,30,30,29,30,29,30,29,29,30,29,30,0,2,2),
86=>array(0,29,30,30,29,30,30,29,30,29,30,29,29,0,3,3),
87=>array(6,30,29,30,29,30,30,29,30,30,29,30,29,29,4,4),
88=>array(0,30,29,30,29,30,29,30,30,29,30,30,29,0,5,5),
89=>array(0,30,29,29,30,29,29,30,30,29,30,30,30,0,6,6),
90=>array(5,29,30,29,29,30,29,29,30,29,30,30,30,30,7,7),
91=>array(0,29,30,29,29,30,29,29,30,29,30,30,30,0,8,8),
92=>array(0,29,30,30,29,29,30,29,29,30,29,30,30,0,9,9),
93=>array(3,29,30,30,29,30,29,30,29,29,30,29,30,29,10,10),
94=>array(0,30,30,30,29,30,29,30,29,29,30,29,30,0,1,11),
95=>array(8,29,30,30,29,30,29,30,30,29,29,30,29,30,2,12),
96=>array(0,29,30,29,30,30,29,30,29,30,30,29,29,0,3,1),
97=>array(0,30,29,30,29,30,29,30,30,29,30,30,29,0,4,2),
98=>array(5,30,29,29,30,29,29,30,30,29,30,30,29,30,5,3),
99=>array(0,30,29,29,30,29,29,30,29,30,30,30,29,0,6,4),
100=>array(0,30,30,29,29,30,29,29,30,29,30,30,29,0,7,5),
101=>array(4,30,30,29,30,29,30,29,29,30,29,30,29,30,8,6),
102=>array(0,30,30,29,30,29,30,29,29,30,29,30,29,0,9,7),
103=>array(0,30,30,29,30,30,29,30,29,29,30,29,30,0,10,8),
104=>array(2,29,30,29,30,30,29,30,29,30,29,30,29,30,1,9),
105=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,2,10),
106=>array(7,30,29,30,29,30,29,30,29,30,30,29,30,30,3,11),
107=>array(0,29,29,30,29,29,30,29,30,30,30,29,30,0,4,12),
108=>array(0,30,29,29,30,29,29,30,29,30,30,29,30,0,5,1),
109=>array(5,30,30,29,29,30,29,29,30,29,30,29,30,30,6,2),
110=>array(0,30,29,30,29,30,29,29,30,29,30,29,30,0,7,3),
111=>array(0,30,29,30,30,29,30,29,29,30,29,30,29,0,8,4),
112=>array(4,30,29,30,30,29,30,29,30,29,30,29,30,29,9,5),
113=>array(0,30,29,30,29,30,30,29,30,29,30,29,30,0,10,6),
114=>array(9,29,30,29,30,29,30,29,30,30,29,30,29,30,1,7),
115=>array(0,29,30,29,29,30,29,30,30,30,29,30,29,0,2,8),
116=>array(0,30,29,30,29,29,30,29,30,30,29,30,30,0,3,9),
117=>array(6,29,30,29,30,29,29,30,29,30,29,30,30,30,4,10),
118=>array(0,29,30,29,30,29,29,30,29,30,29,30,30,0,5,11),
119=>array(0,30,29,30,29,30,29,29,30,29,29,30,30,0,6,12),
120=>array(4,29,30,30,30,29,30,29,29,30,29,30,29,30,7,1)
);
/*
 *农历天干
 */
$mten=array("null","甲","乙","丙","丁","戊","己","庚","辛","壬","癸");
//农历地支
$mtwelve=array("null","子(鼠)","丑(牛)","寅(虎)","卯(兔)","辰(龙)",
               "巳(蛇)","午(马)","未(羊)","申(猴)","酉(鸡)","戌(狗)","亥(猪)");
//农历月份
$mmonth=array("闰","正","二","三","四","五","六",
              "七","八","九","十","十一","十二","月");
//农历日
$mday=array("null","初一","初二","初三","初四","初五","初六","初七","初八","初九","初十",
            "十一","十二","十三","十四","十五","十六","十七","十八","十九","二十",
            "廿一","廿二","廿三","廿四","廿五","廿六","廿七","廿八","廿九","三十");
/*
 *赋给初值
 *天干地支
*/
$ten=0;
$twelve=0;
//星期
$week=5;
//农历日
$md=0;
//农历月
$mm=0;
//阳历总天数 至1900年12月21日
$total=11;
//阴历总天数
$mtotal=0;
/*
 *获得当日日期
 */
$today=getdate();
//如果没有输入,设为当日日期
if ($year=="" or $month=="" or ($year<1901 or $year>2020)
    or ($month<1 or $month>12)){
     $year=$today[year];
     $month=$today[mon];
   }
/*
 *计算到所求日期阳历的总天数-自1900年12月21日始
 *先算年的和
 */
for ($y=1901;$y<$year;$y++){
      $total+=365;
      if ($y%4==0) $total ++;
    }
//再加当年的几个月
switch ($month){
         case 12:
              $total+=30;
         case 11:
              $total+=31;
         case 10:
              $total+=30;
         case 9:
              $total+=31;
         case 8:
              $total+=31;
         case 7:
              $total+=30;
         case 6:
              $total+=31;
         case 5:
              $total+=30;
         case 4:
              $total+=31;
         case 3:
              $total+=28;
         case 2:
              $total+=31;
       }
//如果当年是闰年还要加一天
if ($year%4==0 and $month>2){
     $total++;
    }
//顺便算出当月1日星期几
$week=($total+$week)%7;
/*
 *用农历的天数累加来判断是否超过阳历的天数
 */
$flag1=0;//判断跳出循环的条件
$j=0;
while ($j<=120){
      $i=1;
      while ($i<=13){
            $mtotal+=$everymonth[$j][$i];
            if ($mtotal>=$total){
                 $flag1=1;
                 break;
               }
            $i++;
          }
      if ($flag1==1) break;
      $j++;
    }
/*
 *计算所求月份1号的农历日期
 */
$md=$everymonth[$j][$i]-($mtotal-$total);
//月头空开的天数
$k=$week;
//是否跨越一年
switch ($month){
         case 1:
         case 3:
         case 5:
         case 7:
         case 8:
         case 10:
         case 12:
              $dd=31;
              break;
         case 4:
         case 6:
         case 9:
         case 11:
              $dd=30;
              break;
         case 2:
              if ($year%4==0){
                  $dd=29;
                 }else{
                  $dd=28;
                 }
              break;
       }
//是否跨越一年
$ty=0;
if ((($everymonth[$j][0]<>0 and $i==13) or ($everymonth[$j][0]==0 and $i==12))
       and $mtotal-$total<$dd) $ty=1;
?>
<html>
<head>
<title>世纪万年历</title>
<style type="text/css">
<!--
input { font-size:9pt;}
A:link {text-decoration: underline; font-size:9pt;color:000059}
A:visited {text-decoration: underline; font-size:9pt;color:000059}
A:active {text-decoration: none; font-size:9pt}
A:hover {text-decoration:underline;color:red}
body,table {font-size: 9pt}
tr,td{font-size:9pt}
-->
</style>
</head>
<body alink="#FF0000" link="#000099" vlink="#CC6600" topmargin="8" leftmargin="0" bgColor="#FFFFFF">
<?
 //打印年月抬头
 echo "<p align="center"><font size="6"><b>".$year."年".$month."月</b></font></p>n";
 if($ty==0)
 {
  echo "<p align="center"><b><font size="4">".$mten[$everymonth[$j][14]].$mtwelve[$everymonth[$j][15]]."年</font></b></p>";
 }
 else
 {
  echo "<p align="center"><b><font size="4">".$mten[$everymonth[$j][14]].$mtwelve[$everymonth[$j][15]]."/".$mten[$everymonth[$j+1][14]].$mtwelve[$everymonth[$j+1][15]]."年</font></b></p>";
 }
?>
<div align="center">
  <center>
  <table border="1" width="85%">
    <tr>
      <td align="center" bgcolor="#CCCCCC"><font color="#FF0000"><b>星期日</b></font></td>
      <td width="14%" align="center" bgcolor="#CCCCCC"><b>星期一</b></td>
      <td width="14%" align="center" bgcolor="#CCCCCC"><b>星期二</b></td>
      <td width="14%" align="center" bgcolor="#CCCCCC"><b>星期三</b></td>
      <td width="14%" align="center" bgcolor="#CCCCCC"><b>星期四</b></td>
      <td width="14%" align="center" bgcolor="#CCCCCC"><b>星期五</b></td>
      <td width="14%" align="center" bgcolor="#CCCCCC"><b>星期六</b></td>
    </tr>
<?
$day=1;
$line=0;
while ($day<=$dd){
   echo "<tr>n";
   for ($s=0;$s<=6;$s++){
         if ($k<>0 or $day>$dd){
              echo "<td width="14%" align="center"> </td>n";
              $k--;
         }else{
 //设置字符颜色
               switch ($s){
                        case 1:
                        case 2:
                        case 3:
                        case 4:
                        case 5:
                             $color="#000000";
                             break;
                        case 0:
                             $color="#FF0000";
                             break;
                        case 6:
                             $color="#008000";
                             break;
                      }
#生成中文农历
               if ($md==1){#1日打印月份
                    if ($everymonth[$j][0]<>0 and $everymonth[$j][0]<$i){
                        $mm=$i-1;
                    }else{
                        $mm=$i;
                    }
                    if ($i==$everymonth[$j][0]+1 and $everymonth[$j][0]<>0) $chi=$mmonth[0].$mmonth[$mm];#闰月
                    else $chi=$mmonth[$mm].$mmonth[13];
               }else{
                    $chi=$mday[$md];
               }
               echo "<td width="14%" align="center"><font color="$color"><b>$day </b> <b><font size="2">$chi</font></b></font></td>n";
               $day++;
               $md++;
               if ($md>$everymonth[$j][$i]){
                    $md=1;
                    $i++;
                  }
               if (($i>12 and $everymonth[$j][0]==0) or ($i>13 and $everymonth[$j][0]<>0)){
                     $i=1;
                     $j++;
                  }
           }
       }
   echo "</tr>n";
   $line++;
}
?>
  </table>
  </center>
</div>
<?php
#补足空行
for ($l=1;$l<=(6-$line);$l++){
      echo "<table border="0" width="100%">n";
      echo "<tr>n";
      echo "<td width="100%"><font color="#CCFFFF">a</font></td>n";
      echo "</tr>n";
      echo "</table>n";
    }
#打印上一月,下一月
$ly=$ny=$year;
$last=$month-1;
if ($last==0){
     $last=12;
     $ly--;
   }
$next=$month+1;
if ($next==13){
     $next=1;
     $ny++;
   }
if ($ly>=1901)
echo "<p align="center"><a href="".$file."?year=".$ly."&month=".$last.""><<上一个月</a>   n";
else
echo "<p align="center">";
if ($ny<=2020)
echo "<a href="".$file."?year=".$ny."&month=".$next."">下一个月>></a></p>n";
?>
 <?php
echo "<form method="POST" action="".$file."">n";
?>
  <p align="center"><font color="#000000">年份:</font><select size="1" name="year">
<?php
for($i=2020;$i>1900;$i--)
echo <option>.$i.</option>;
?>
  
  </select><font color="#000000">年</font><font color="#000000">   
  月份:<select size="1" name="month">
<?php
for($j=1;$j<=12;$j++)
echo <option>.$j.</option>;
?>
 
  </select>月     </font><input type="submit" value="查询" name="B1"></p>
</form>
</body>
</html>

阅读全文

php 给图片加水印

<?php
   /*   ClassName: ImageHandler
    *   Filename:  ImageHandler.phpcls
    *   Author:    Tony Don
    *   Date:      2008-03-27
    *   @Copyright txdnet.com
    *   Function:  Handler Images
    */
 
class ImageHandler
{
    var $dst_img;// 目标文件
    var $h_src; // 图片资源句柄
    var $h_dst;// 新图句柄
    var $h_mask;// 水印句柄
    var $img_create_quality = 100;// 图片生成质量
    var $img_display_quality = 80;// 图片显示质量,默认为75
    var $img_scale = 0;// 图片缩放比例
    var $src_w = 0;// 原图宽度
    var $src_h = 0;// 原图高度
    var $dst_w = 0;// 新图总宽度
    var $dst_h = 0;// 新图总高度
    var $fill_w;// 填充图形宽
    var $fill_h;// 填充图形高
    var $copy_w;// 拷贝图形宽
    var $copy_h;// 拷贝图形高
    var $src_x = 0;// 原图绘制起始横坐标
    var $src_y = 0;// 原图绘制起始纵坐标
    var $start_x;// 新图绘制起始横坐标
    var $start_y;// 新图绘制起始纵坐标
    var $mask_word;// 水印文字
    var $mask_img;// 水印图片
    var $mask_pos_x = 0;// 水印横坐标
    var $mask_pos_y = 0;// 水印纵坐标
    var $mask_offset_x = 5;// 水印横向偏移
    var $mask_offset_y = 5;// 水印纵向偏移
    var $font_w;// 水印字体宽
    var $font_h;// 水印字体高
    var $mask_w;// 水印宽
    var $mask_h;// 水印高
    var $mask_font_color = "#000000";// 水印文字颜色
    var $mask_font = 5;// 水印字体
    var $font_size;// 尺寸
    var $mask_position = 0;// 水印位置
    var $mask_img_pct = 50;// 图片合并程度,值越大,合并程序越低
    var $mask_txt_pct = 50;// 文字合并程度,值越小,合并程序越低
    var $img_border_size = 0;// 图片边框尺寸
    var $img_border_color;// 图片边框颜色
    var $_flip_x=0;// 水平翻转次数
    var $_flip_y=0;// 垂直翻转次数
    var $cut_type=0;// 剪切或缩小类型
    var $img_type;// 文件类型
 
    // 文件类型定义,并指出了输出图片的函数
    var $all_type = array(
        "jpg"  => array("output"=>"imagejpeg"),
        "gif"  => array("output"=>"imagegif"),
        "png"  => array("output"=>"imagepng"),
        "wbmp" => array("output"=>"image2wbmp"),
        "jpeg" => array("output"=>"imagejpeg"));
    /**
     * 构造函数
     */
    function ImageHandler()
    {
        $this->mask_font_color = "#ffffff";
        $this->font = 2;
        $this->font_size = 12;
    }
    /**
     * 取得图片的宽
     */
    function getImgWidth($src)
    {
        return imagesx($src);
    }
    /**
     * 取得图片的高
     */
    function getImgHeight($src)
    {
        return imagesy($src);
    }
    /**
     * 设置图片生成路径
     *
     * @param    string    $src_img   图片生成路径
     */
    function setSrcImg($src_img, $img_type=null)
    {
        if(!file_exists($src_img))
        {
            die("图片不存在");
        }
       
        if(!empty($img_type))
        {
            $this->img_type = $img_type;
        }
        else
        {
            $this->img_type = $this->_getImgType($src_img);
        }
       
        $this->_checkValid($this->img_type);
 
        // file_get_contents函数要求php版本>4.3.0
        $src = ;
        if(function_exists("file_get_contents"))
        {
            $src = file_get_contents($src_img);
        }
        else
        {
            $handle = fopen ($src_img, "r");
            while (!feof ($handle))
            {
                $src .= fgets($fd, 4096);
            }
            fclose ($handle);
        }
        if(empty($src))
        {
            die("图片源为空");
        }
        $this->h_src = @ImageCreateFromString($src);
        $this->src_w = $this->getImgWidth($this->h_src);
        $this->src_h = $this->getImgHeight($this->h_src);
    }
 
    /**
     * 设置图片生成路径
     *
     * @param    string    $dst_img   图片生成路径
     */
    function setDstImg($dst_img)
    {
        $arr  = explode(/,$dst_img);
        $last = array_pop($arr);
        $path = implode(/,$arr);
        $this->_mkdirs($path);
        $this->dst_img = $dst_img;
    }
 
    /**
     * 设置图片的显示质量
     *
     * @param    string      $n    质量
     */
    function setImgDisplayQuality($n)
    {
        $this->img_display_quality = (int)$n;
    }
 
    /**
     * 设置图片的生成质量
     *
     * @param    string      $n    质量
     */
    function setImgCreateQuality($n)
    {
        $this->img_create_quality = (int)$n;
    }
 
    /**
     * 设置文字水印
     *
     * @param    string     $word    水印文字
     * @param    integer    $font    水印字体
     * @param    string     $color   水印字体颜色
     */
    function setMaskWord($word)
    {
        $this->mask_word .= $word;
    }
 
    /**
     * 设置字体颜色
     *
     * @param    string     $color    字体颜色
     */
    function setMaskFontColor($color="#ffffff")
    {
        $this->mask_font_color = $color;
    }
 
   ?>

阅读全文

php批量上传三[带预览]

<?php
if($_POST[upload]==提交){
//*******************************************************
//**批量上传**********************************************
                function saveImage ($im , $filename)
            {
                          $r = imagejpeg ($im , $filename);
     
                         if($r){
                        echo "";
                         }
                     else{
                        echo "";
                         }

             }

             function Makesuo ($img_path,$img_name,$img_type)
                         {

                  $open_file = $img_path.$img_name;

                  $file_type = $img_type;

                  if($file_type == "jpg"){

                      $source = imagecreatefromjpeg($open_file);

                  }
                  elseif($file_type == "gif"){

                      $source = imagecreatefromgif($open_file);

                  }
                  elseif($file_type =="png"){

                      $source = imagecreatefrompng($open_file);

                  }

                  $size = getimagesize($open_file);

                  $size_wei = $size[0];

                  $size_hei = $size[1];

                  $pic_bi = $size_wei/$size_hei;

                  if($pic_bi>1.2){

                  $new_wei = $size_hei*1.2;

                  $new_hei = $size_hei;

                  $loda_point = ($size_wei-$new_wei)/2;

                  $target1 = imagecreatetruecolor(120,100);

                  imagecopyresized($target1,$source,0,0,$loda_point,0,120,100,$new_wei,$new_hei);

                  saveImage($target1, "../suo_img/suo_".$img_name,$file_type);

                  return "../suo_img/suo_".$img_name;

                  imagedestroy($source);

                  imagedestroy($target1);

                  }


                   elseif($pic_bi <= 1.2 && $pic_bi >= 1){
                   $new_wei = $size_hei*1.2;

                   $new_hei = $size_hei;

                   $loda_point = ($size_wei-$new_wei)/2;

                   $target1 = imagecreatetruecolor(120,100);

                   imagecopyresized($target1,$source,0,0,$loda_point,0,120,100,$new_wei,$new_hei);

                   saveImage($target1, "../suo_img/suo_".$img_name,$file_type);

                   return "../suo_img/suo_".$img_name;

                   imagedestroy($source);

                   imagedestroy($target1);
                   }


                   elseif($pic_bi < 1){

                   $new_hei = $size_wei*1.2;

                   $new_wei = $size_wei;

                   $loda_point = ($size_hei-$new_hei)/2;

                   $target1 = imagecreatetruecolor(120,100);

                   imagecopyresized($target1,$source,0,0,0,$loda_point,120,100,$new_wei,$new_hei);

                   saveImage($target1, "../suo_img/suo_".$img_name,$file_type);

                   return "../suo_img/suo_".$img_name;

                   imagedestroy($source);

                   imagedestroy($target1);

                   }
             }

阅读全文

php批量上传二[带预览]

<?php
$id = $_GET[id];
$sql = "select * from biao where pid=".$id;
$res = mysqli_query($conn,$sql);
$num = mysqli_num_rows($res);   //现有多少张图片
$sql1 = "select * from biao where id=".$id;
$res1 = mysqli_query($conn,$sql1);
$row1 = mysqli_fetch_assoc($res1);
$num1 = $row1[p_num];
$p_name = $row1[p_name];
?>

<form action="" method="post" enctype="multipart/form-data" name="form2">
<br>
<table width="750" border="1" align="center" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td height="25"  width="550" align="center" valign="middle" bgcolor="#FFFFFF"><font size="5">添  加  图  片</font></td>
<td height="25"  align="center" valign="middle" bgcolor="#FFFFFF"><input type="submit" name="fanhui" value="返回上一层"></td>
</tr>
</table>
<br>



<table width="750" border="1" align="center" cellpadding="0" cellspacing="1" bgcolor="#FFFFCC">
<tr>
    <td align="center" colspan="2">
  <p align="left"> 现已上传图片<?php echo $num?>张:</p>
  <p>图片名称1:<input type="text" name="name[]" size="25"><input type="hidden" name="tu1"/>  <input type="file" name="pictures[]" id="file1"  /></p><p></p>
  <p>图片名称2:<input type="text" name="name[]" size="25"><input type="hidden" name="tu2"/>  <input type="file" name="pictures[]" id="file2" /></p><p></p>
  <p>图片名称3:<input type="text" name="name[]" size="25">  <input type="file" name="pictures[]" id="file3" /></p><p></p>
  <p>图片名称4:<input type="text" name="name[]" size="25">  <input type="file" name="pictures[]" id="file1"  /></p><p></p>
  <input type="submit" name="upload" value="提交" />
  </td>
</tr>
</table>
  
</form>
</body>
</html>

阅读全文

PHP多文件上传分析

多文件上传是PHP中一基础应用,在此把相关知识向大家详细介绍一下,本人水平有限,还请多提意见。大家一起进步。
        上传文件HTML的输入标签FILE类型中的名称后要加[],作用是在HTML中向PHP建立数组,比如名称为pictures,多文件引用名称则为pictures[],实例如下:

阅读全文

php批量上传一[带预览]

代码如下:

<?php
require(inc/conn.php);
?>
<head>
<head>
<meta http-equiv="Content-Type" c />
<title>图片上传实现</title>
<script language="javascript">
function preview(x){
    if(!x || !x.value) return;
    var patn = /.jpg$|.jpeg$|.gif$/i;
    if(patn.test(x.value)){
        if(x.parentNode.nextSibling.firstChild){
            //看看是不是已经添加了图片标签,如果添加了就直接修改图片地址
            x.parentNode.nextSibling.firstChild.setAttribute(src,file://localhost/+x.value);
        }else{
            //没添加就创建个咯,然后加入到当前节点的父节点的下一个节点 -_-
            var img = document.createElement(img);
            img.setAttribute(src,file://localhost/+x.value);
            img.setAttribute(width,120);
            img.setAttribute(height,100);
            x.parentNode.nextSibling.appendChild(img);
            //parentNode  父节点
            //nextSibling 下个节点
            //appendChild 添加个子节点
                        return(x.value);
        }
    }else{
        alert(貌似你选的不是个图片的说!);
        x.value=;                            //本人不懂js,考来的,对不住各位了,也谢谢原作者!
    }
}
</script>
</head>
</head>
<body>

阅读全文

php ajax 分页一

ajax分页   php ajax分页   java ajax分页   asp.net ajax分页  jquery ajax 分页 jsp ajax无刷新分页   asp ajax分页   ajax 分页问题   ajax实现分页   ajax jsp分页
ajax 分页用的是在客户端分析数据,然后再发给php文件进行处理,返回给客户端处理理,思路就是这样的.

阅读全文

php压缩技术

GZIP(GNU-ZIP)是一种压缩技术。经过GZIP压缩后页面大小可以变为原来的30%甚至更小。这样用户浏览的时候就会感觉很爽很愉快!
要实现GZIP压缩页面需要浏览器和服务器共同支持,实际上就是服务器压缩,传到浏览器后浏览器解压并解析。浏览器那边不需要我们担心,因为现在绝大多数浏览器都支持解析GZIP过的页面。我们只要把页面在服务器端压缩再输出到浏览器就行了。

有点罗嗦,下面说正事:
正如要制作压缩饼干,先要拿到原料,要压缩一个页面,首先要获得要输出的内容。PHP中的ob_start()(ob => output buffer)函数可以实现这个功能,它可以把程序里准备输出的内容先放到一个叫做“缓冲区”的地方,当然,你可以理解为制作压缩饼干的暂时放原料的工作台。
这个函数一定要在页面输出之前使用,所以一般把它放在代码的最顶端。因为它就像是一个工作台,所以你要在原料到来之前就要准备好它,否则原料来了没地方放,会出问题的。用ob_start()得到要压缩的页面之后,我们就可以制作压缩饼干了,不对,应该是可以压缩页面了!不过好像还缺少一台压缩机,EZ,我们用PHP带的zlib扩展做一台:

阅读全文

php读取execel内容

<?
define(ABC_CRITICAL,      0);
define(ABC_ERROR,         1);
define(ABC_ALERT,         2);
define(ABC_WARNING,       3);
define(ABC_NOTICE,        4);
define(ABC_INFO,          5);
define(ABC_DEBUG,         6);
define(ABC_TRACE,         7);
define(ABC_VAR_DUMP,      8);
define(ABC_NO_LOG,      -1);
$php_version = split( ".", phpversion() );
if( $php_version[0] == 4 && $php_version[1] <= 1 ) {
    if( !function_exists(var_export) ) {
        function var_export( $exp, $ret ) {
ob_start();
var_dump( $exp );
$result = ob_get_contents();
ob_end_clean();
return $result;
}}}function print_bt()
{
print "<code>n";
$cs = debug_backtrace();
for( $i = 1; $i < count($cs) ; $i++ )
{
$item = $cs[ $i ];
for( $j = 0; $j < count($item[args]); $j++ )
if( is_string($item[args][$j]) )
$item[args][$j] = """ . $item[args][$j] . """;
$args = join(",", $item[args] );
if( isset( $item[class] ) )
$str = sprintf("%s(%d): %s%s%s(%s)",
$item[file],
$item[line],
$item[class],
$item[type],
$item[function],
$args );
else
$str = sprintf("%s(%d): %s(%s)",
$item[file],
$item[line],
$item[function],
$args );
echo $str . "<br>n";
}print "</code>n";
}function _die( $str )
{
print "Script died with reason: $str<br>n";
print_bt();
exit();
}class DebugOut
{
var $priorities = array(ABC_CRITICAL    => critical,
                        ABC_ERROR       => error,
                        ABC_ALERT       => alert,
                        ABC_WARNING     => warning,
                        ABC_NOTICE      => notice,
                        ABC_INFO        => info,
                        ABC_DEBUG       => debug,
                        ABC_TRACE       => trace,
                        ABC_VAR_DUMP        => dump
                        );
var $_ready = false;
var $_currentPriority = ABC_DEBUG;
var $_consumers = array();
var  $_filename;
var  $_fp;
var  $_logger_name;
 function DebugOut($name, $logger_name, $level ){
     $this->_filename = $name;
     $this->_currentPriority = $level;
     $this->_logger_name = $logger_name;
     if ($level > ABC_NO_LOG){
        $this->_openfile();
     }
     register_shutdown_function(array($this,"close"));
 } function log($message, $priority = ABC_INFO) {
        if ($priority > $this->_currentPriority) {
            return false;
        }
        return $this->_writeLine($message, $priority, strftime(%b %d %H:%M:%S));
 } function dump($variable,$name) {
       $priority = ABC_VAR_DUMP;
       if ($priority > $this->_currentPriority ) {
            return false;
       }       $time = strftime(%b %d %H:%M:%S);
       $message = var_export($variable,true);
       return fwrite($this->_fp,
                     sprintf("%s %s [%s] variable %s = %s rn",
                             $time,
                             $this->_logger_name,
                             $this->priorities[$priority],
                             $name,
                             $message)
                             );
 } function info($message) {
        return $this->log($message, ABC_INFO);
 } function debug($message) {
        return $this->log($message, ABC_DEBUG);
 } function notice($message) {
        return $this->log($message, ABC_NOTICE);
 } function warning($message) {
        return $this->log($message, ABC_WARNING);
 } function trace($message) {
        return $this->log($message, ABC_TRACE);
 } function error($message) {
        return $this->log($message, ABC_ERROR);
 }
 function _writeLine($message, $priority, $time) {
    if( fwrite($this->_fp, sprintf("%s %s [%s] %srn", $time, $this->_logger_name, $this->priorities[$priority], $message)) ) {
        return fflush($this->_fp);
    } else {
        return false;
    } } function _openfile() {
    if (($this->_fp = @fopen($this->_filename, a)) == false) {
        return false;
    }        return true;
 } function close(){
    if($this->_currentPriority != ABC_NO_LOG){
        $this->info("Logger stoped");
        return fclose($this->_fp);
    } }
 function Factory($name, $logger_name, $level) {
    $instance = new DebugOut($name, $logger_name, $level);
    return $instance;
 } function &getWriterSingleton($name, $logger_name, $level = ABC_DEBUG){
      static $instances;
      if (!isset($instances)){
        $instances = array();
      }      $signature = serialize(array($name, $level));
      if (!isset($instances[$signature])) {
            $instances[$signature] = DebugOut::Factory($name, $logger_name, $level);
      }     
      return $instances[$signature];
 } function attach(&$logObserver) {
    if (!is_object($logObserver)) {
        return false;
    }    $logObserver->_listenerID = uniqid(rand());
    $this->_listeners[$logObserver->_listenerID] = &$logObserver;
 }}define (ABC_BAD_DATE, -1);
class ExcelDateUtil{
function xls2tstamp($date) {
$date=$date>25568?$date:25569;
   $ofs=(70 * 365 + 17+2) * 86400;
   return ($date * 86400) - $ofs;
}function getDateArray($xls_date){
    $ret = array();
    if ($xls_date == 60) {
        $ret[day]   = 29;
        $ret[month] = 2;
        $ret[year]  = 1900;
        return $ret;
    } else if ($xls_date < 60) {
         $xls_date++;
    }
    $l = $xls_date + 68569 + 2415019;
    $n = (int)(( 4 * $l ) / 146097);
    $l = $l - (int)(( 146097 * $n + 3 ) / 4);
    $i = (int)(( 4000 * ( $l + 1 ) ) / 1461001);
    $l = $l - (int)(( 1461 * $i ) / 4) + 31;
    $j = (int)(( 80 * $l ) / 2447);
    $ret[day] = $l - (int)(( 2447 * $j ) / 80);
    $l = (int)($j / 11);
    $ret[month] = $j + 2 - ( 12 * $l );
    $ret[year] = 100 * ( $n - 49 ) + $i + $l;
    return $ret;
}function isInternalDateFormat($format) {
    $retval =false;
    switch(format) {
        case 0x0e:
        case 0x0f:
        case 0x10:
        case 0x11:
        case 0x12:
        case 0x13:
        case 0x14:
        case 0x15:
        case 0x16:
        case 0x2d:
        case 0x2e:
        case 0x2f:
        case 0xa4:
        case 0xa5:
        case 0xa6:
        case 0xa7:
        case 0xa8:
        case 0xa9:
        case 0xaa:
        case 0xab:
        case 0xac:
        case 0xad:
        $retval = true; break;
        default: $retval = false; break;
    }         return $retval;
}}define(EXCEL_FONT_RID,0x31);
define(XF_SCRIPT_NONE,0);
define(XF_SCRIPT_SUPERSCRIPT,1);
define(XF_SCRIPT_SUBSCRIPT,2);
define(XF_UNDERLINE_NONE,0x0);
define(XF_UNDERLINE_SINGLE,0x1);
define(XF_UNDERLINE_DOUBLE,0x2);
define(XF_UNDERLINE_SINGLE_ACCOUNTING,0x3);
define(XF_UNDERLINE_DOUBLE_ACCOUNTING,0x4);
define(XF_STYLE_ITALIC, 0x2);
define(XF_STYLE_STRIKEOUT, 0x8);
define(XF_BOLDNESS_REGULAR,0x190);
define(XF_BOLDNESS_BOLD,0x2BC);
class ExcelFont {
 function basicFontRecord() {
    return  array(size     => 10,
                    script   => XF_SCRIPT_NONE,
                    undeline => XF_UNDERLINE_NONE,
                    italic   => false,
                    strikeout=> false,
                    bold     => false,
                    boldness => XF_BOLDNESS_REGULAR,
                    palete   => 0,
                    name     => Arial);
 } function getFontRecord(&$wb,$ptr) {
    $retval = array(size     => 0,
                    script   => XF_SCRIPT_NONE,
                    undeline => XF_UNDERLINE_NONE,
                    italic   => false,
                    strikeout=> false,
                    bold     => false,
                    boldness => XF_BOLDNESS_REGULAR,
                    palete   => 0,
                    name     => );
    $retval[size] = (ord($wb[$ptr])+ 256*ord($wb[$ptr+1]))/20;
    $style=ord($wb[$ptr+2]);
    if (($style & XF_STYLE_ITALIC) != 0) {
        $retval[italic] = true;
    }    if (($style & XF_STYLE_STRIKEOUT) != 0) {
        $retval[strikeout] = true;
    }    $retval[palete] = ord($wb[$ptr+4])+256*ord($wb[$ptr+5]);
    $retval[boldness] = ord($wb[$ptr+6])+256*ord($wb[$ptr+7]);
    $retval[bold] = $retval[boldness] == XF_BOLDNESS_REGULAR ? false:true;
    $retval[script] =  ord($wb[$ptr+8])+256*ord($wb[$ptr+9]);
    $retval[underline] = ord($wb[$ptr+10]);
    $length = ord($wb[$ptr+14]);
    if($length >0) {
        if(ord($wb[$ptr+15]) == 0) {
            $retval[name] = substr($wb,$ptr+16,$length);
        } else {
            $retval[name] = ExcelFont::getUnicodeString($wb,$ptr+15,$length);
        }    }    return $retval;
 } function toString(&$record,$index) {
    $retval = sprintf("Font Index = %d nFont Size =%dnItalic = %snStrikeoout=%snPalete=%snBoldness = %s Bold=%sn Script = %dn Underline = %dn FontName=%s<hr>",
                $index,
                $record[size],
                $record[italic]    == true?"true":"false",
                $record[strikeout] == true?"true":"false",
                $record[palete],
                $record[boldness],
                $record[bold] == true?"true":"false",
                $record[script],
                $record[underline],
                $record[name]
                );
    return $retval;
 } function getUnicodeString(&$string,$offset,$length) {
        $bstring = "";
        $index   = $offset + 1;
        for ($k = 0; $k < $length; $k++)
        {
            $bstring = $bstring.$string[$index];
            $index        += 2;
        }        return substr($bstring,0,$length);
 } function ExcelToCSS($rec, $app_font=true, $app_size=true, $app_italic=true, $app_bold=true){
    $ret = "";
    if($app_font==true){
        $ret = $ret."font-family:".$rec[name]."; ";
    }    if($app_size==true){
        $ret = $ret."font-size:".$rec[size]."pt; ";
    }    if($app_bold==true){
        if($rec[bold]==true){
            $ret = $ret."font-weight:bold; ";
        } else {
            $ret = $ret."font-weight:normal; ";
        }    }    if($app_italic==true){
        if($rec[italic]==true){
            $ret = $ret."font-style:italic; ";
        } else {
            $ret = $ret."font-style:normal; ";
        }    }    return $ret;
 }}define ( DP_EMPTY, 0 );
define ( DP_STRING_SOURCE, 1 );
define ( DP_FILE_SOURCE, 2 );
class ExcelParserUtil
{
function str2long($str) {
return ord($str[0]) + 256*(ord($str[1]) +
256*(ord($str[2]) + 256*(ord($str[3])) ));
}}
class DataProvider
{
function DataProvider( $data, $dataType )
{
switch( $dataType )
{
case DP_FILE_SOURCE:
if( !( $this->_data = @fopen( $data, "rb" )) )
return;
$this->_size = @filesize( $data );
if( !$this->_size )
_die("Failed to determine file size.");
break;
case DP_STRING_SOURCE:
$this->_data = $data;
$this->_size = strlen( $data );
break;
default:
_die("Invalid data type provided.");
}$this->_type = $dataType;
register_shutdown_function( array( $this, "close") );
}function get( $offset, $length )
{
if( !$this->isValid() )
_die("Data provider is empty.");
if( $this->_baseOfs + $offset + $length > $this->_size )
_die("Invalid offset/length.");
switch( $this->_type )
{
case DP_FILE_SOURCE:
{
if( @fseek( $this->_data, $this->_baseOfs + $offset, SEEK_SET ) == -1 )
_die("Failed to seek file position specified by offest.");
return @fread( $this->_data, $length );
}case DP_STRING_SOURCE:
{
$rc = substr( $this->_data, $this->_baseOfs + $offset, $length );
return $rc;
}default:
_die("Invalid data type or class was not initialized.");
}}function getByte( $offset )
{
return $this->get( $offset, 1 );
}function getOrd( $offset )
{
return ord( $this->getByte( $offset ) );
}function getLong( $offset )
{
$str = $this->get( $offset, 4 );
return ExcelParserUtil::str2long( $str );
}function getSize()
{
if( !$this->isValid() )
_die("Data provider is empty.");
return $this->_size;
}function getBlocks()
{
if( !$this->isValid() )
_die("Data provider is empty.");
return (int)(($this->_size - 1) / 0x200) - 1;
}function ReadFromFat( $chain, $gran = 0x200 )
{
$rc = ;
for( $i = 0; $i < count($chain); $i++ )
$rc .= $this->get( $chain[$i] * $gran, $gran );
return $rc;
}function close()
{
switch($this->_type )
{
case DP_FILE_SOURCE:
@fclose( $this->_data );
case DP_STRING_SOURCE:
$this->_data = null;
default:
$_type = DP_EMPTY;
break;
}}function isValid()
{
return $this->_type != DP_EMPTY;
}var $_type = DP_EMPTY;
var $_data = null;
var $_size = -1;
var $_baseOfs = 0;
}class ExcelFileParser {
var $dp = null;
var $max_blocks;
var $max_sblocks;
var $fat;
var $sfat;
var $formats;
var $xf;
var $fonts;
    var $dbglog;

阅读全文