php 文件上传类
代码如下 | 复制代码 |
<?php class Uploader function Uploader( $base_dir, $rel_dir ) if( $result != 'Success' ) |
真正支持单文件和多文件上传类代码,修正了$_FILES[$field]['name']中的$field不能用变量只能和表单中的文件名name="userfile"一致的缺点$_FILES['userfile']['name'],这里<input type="file" name="userfile"> 中的文件名可以随意取。
//index.htm
1、单文件上传
<form method="post" action="./upload.php" name="frmUpload" enctype="multipart/form-data" >
<input type="file" name="userfile" style="WIDTH: 282px">
<input type="submit" align="center" name="upfiles" value="确定"></form>
2、多文件上传
<form method="post" action="./upload.php" name="frmUpload" enctype="multipart/form-data" >
<input type="file" name="userfile[]" style="WIDTH: 282px">
<input type="file" name="userfile[]" style="WIDTH: 282px">
<input type="file" name="userfile[]" style="WIDTH: 282px">
<input type="submit" align="center" name="upfiles" value="确定">
</form>
--------------------------------------------------------------------------------------------------------------------------------
//upload.php
<?php
class File_upload{
public $upload_path='./upload/';//上传文件的路径
public $allow_type=array();//允许上传的文件类型
public $max_size='20480';//允许的最大文件大小
public $overwrite=false;//是否设置成覆盖模式
public $renamed=false;//是否直接使用上传文件的名称,还是系统自动命名
/**
* 私有变量
*/
private $upload_file=array();//保存上传成功文件的信息
private $upload_file_num=0;//上传成功文件的数目
private $succ_upload_file=array();//成功保存的文件信息
/**
* 构造器
*
* @param string $upload_path
* @param string $allow_type
* @param string $max_size
*/
public function __construct($upload_path='./upload/',$allow_type='jpg|bmp|png|gif|jpeg',$max_size='204800')
{
$this->set_upload_path($upload_path);
$this->set_allow_type($allow_type);
$this->max_size=$max_size;
$this->get_upload_files();
}
/**
* 设置上传路径,并判定
*
* @param string $path
*/
public function set_upload_path($path)
{
if(file_exists($path)){
if(is_writeable($path)){
$this->upload_path=$path;
}else{
if(@chmod($path,'0666'))
$this->upload_path=$path;
}
}else{
if(@mkdir($path,'0666')){
$this->upload_path=$path;
}
}
}
//设置上传文件类型
public function set_allow_type($types){
$this->allow_type=explode("|",$types);
}
//上传文件
public function get_upload_files()
{
foreach ($_FILES AS $key=>$field)
{
$this->get_upload_files_detial($key);
}
}
//上传文件数据存放到数组中
public function get_upload_files_detial($field){
if(is_array($_FILES["$field"]['name']))
{
for($i=0;$i<count($_FILES[$field]['name']);$i++)
{
if(0==$_FILES[$field]['error'][$i])
{
$this->upload_file[$this->upload_file_num]['name']=$_FILES[$field]['name'][$i];
$this->upload_file[$this->upload_file_num]['type']=$_FILES[$field]['type'][$i];
$this->upload_file[$this->upload_file_num]['size']=$_FILES[$field]['size'][$i];
$this->upload_file[$this->upload_file_num]['tmp_name']=$_FILES[$field]['tmp_name'][$i];
$this->upload_file[$this->upload_file_num]['error']=$_FILES[$field]['error'][$i];
$this->upload_file_num++;
}
}
}
else {
if(0==$_FILES["$field"]['error'])
{
$this->upload_file[$this->upload_file_num]['name']=$_FILES["$field"]['name'];
$this->upload_file[$this->upload_file_num]['type']=$_FILES["$field"]['type'];
$this->upload_file[$this->upload_file_num]['size']=$_FILES["$field"]['size'];
$this->upload_file[$this->upload_file_num]['tmp_name']=$_FILES["$field"]['tmp_name'];
$this->upload_file[$this->upload_file_num]['error']=$_FILES["$field"]['error'];
$this->upload_file_num++;
}
}
}
/**
* 检查上传文件是构满足指定条件
*
*/
public function check($i)
{
if(!empty($this->upload_file[$i]['name'])){
//检查文件大小
if($this->upload_file[$i]['size']>$this->max_size*1024)$this->upload_file[$i]['error']=2;
//设置默认服务端文件名
$this->upload_file[$i]['filename']=$this->upload_path.$this->upload_file[$i]['name'];
//获取文件路径信息
$file_info=pathinfo($this->upload_file[$i]['name']);
//获取文件扩展名
$file_ext=$file_info['extension'];
//检查文件类型
if(!in_array($file_ext,$this->allow_type))$this->upload_file[$i]['error']=5;
//需要重命名的
if($this->renamed){
list($usec, $sec) = explode(" ",microtime());
$this->upload_file[$i]['filename']=$sec.substr($usec,2).'.'.$file_ext;
unset($usec);
unset($sec);
}
//检查文件是否存在
if(file_exists($this->upload_file[$i]['filename'])){
if($this->overwrite){
@unlink($this->upload_file[$i]['filename']);
}else{
$j=0;
do{
$j++;
$temp_file=str_replace('.'.$file_ext,'('.$j.').'.$file_ext,$this->upload_file[$i]['filename']);
}while (file_exists($temp_file));
$this->upload_file[$i]['filename']=$temp_file;
unset($temp_file);
unset($j);
}
}
//检查完毕
} else $this->upload_file[$i]['error']=6;
}
/**
* 上传文件
*
* @return true
*/
public function upload()
{
$upload_msg='';
for($i=0;$i<$this->upload_file_num;$i++)
{
if(!empty($this->upload_file[$i]['name']))
{
//检查文件
$this->check($i);
if (0==$this->upload_file[$i]['error'])
{
//上传文件
if(!@move_uploaded_file($this->upload_file[$i]['tmp_name'],$this->upload_file[$i]['filename']))
{
$upload_msg.='上传文件'.$this->upload_file[$i]['name'].' 出错:'.$this->error($this->upload_file[$i]['error']).'!<br>';
}else
{
$this->succ_upload_file[]=$this->upload_file[$i]['filename'];
$upload_msg.='上传文件'.$this->upload_file[$i]['name'].' 成功了<br>';
}
}else $upload_msg.='上传文件'.$this->upload_file[$i]['name'].' 出错:'.$this->error($this->upload_file[$i]['error']).'!<br>';
}
}
echo $upload_msg;
}
//错误信息
public function error($error)
{
switch ($error) {
case 1:
return '文件大小超过php.ini 中 upload_max_filesize 选项限制的值';
break;
case 2:
return '文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值';
break;
case 3:
return '文件只有部分被上传';
break;
case 4:
return '没有文件被上传';
break;
case 5:
return '这个文件不允许被上传';
break;
case 6:
return '文件名为空';
break;
default:
return '出错';
break;
}
}
//获取成功的数据信息为数组(备用)
public function get_succ_file(){
return $this->succ_upload_file;
}
}
$upload=new File_upload('./upload/','jpg|bmp|png|gif|jpeg');
$upload->upload();
$t=$upload->get_succ_file();
print_r($t);
?>
投票系统防刷代码
$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.net
$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.net
}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.net
*/
@mysql_query("update g set visited=visited+1 where id=$this->u_id");
}
/*
get real IP
*/
function lock_user_ip(){
$Usql =mysql_query("select * from su_lockip");
$Urs =mysql_fetch_array($Usql);
$UlockIp=$Urs['lockip'];
$ClockIp=$this->get_real_ip();
$Iplist =explode('|',$UlockIp);
if(in_array($ClockIp,$Iplist)){
exit('sorry system lock your IP');
}
}
function get_real_ip(){
$ip=false;
if(!empty($_SERVER["HTTP_CLIENT_IP"])){
$ip = $_SERVER["HTTP_CLIENT_IP"];
}
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ips = explode (", ", $_SERVER['HTTP_X_FORWARDED_FOR']);
if ($ip) { array_unshift($ips, $ip); $ip = FALSE; }
for ($i = 0; $i < count($ips); $i++) {
if (!eregi ("^(10|172\.16|192\.168)\.", $ips[$i])) {
$ip = $ips[$i];
break;
}
}
}
return ($ip ? $ip : $_SERVER['REMOTE_ADDR']);
}
<?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文件的位置
$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入门者会有不小帮助哦。 简介 Class.upload.php是用于管理上传文件的php文件上传类, 它可以帮...2016-11-25
- 又码了一个周末的代码,这次在做一些关于文件上传的东西。(PHP UPLOAD)小有收获项目是一个BT种子列表,用户有权限上传自己的种子,然后配合BT TRACK服务器把种子的信息写出来...2016-11-25
- 本文实例讲述了jQuery实现文件上传进度条效果的代码。分享给大家供大家参考。具体如下: 运行效果截图如下:具体代码如下:<!DOCTYPE html><html><head><meta charset="utf-8"><title>upload</title><link rel="stylesheet...2015-11-24
- 本篇文章主要说明的是与php文件上传的相关配置的知识点。PHP文件上传功能配置主要涉及php.ini配置文件中的upload_tmp_dir、upload_max_filesize、post_max_size等选项,下面一一说明。打开php.ini配置文件找到File Upl...2015-10-21
借助FileReader实现将文件编码为Base64后通过AJAX上传
这篇文章主要介绍了借助FileReader实现将文件编码为Base64后通过AJAX上传的方法,包括后端对文件数据解码并保存的PHP代码,需要的朋友可以参考下...2015-12-25- 这篇文章主要为大家详细介绍了js实现上传文件添加和删除文件选择框 ,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2016-10-25
- 这篇文章主要介绍了jQuery+ajax简单实现文件上传的方法,结合实例形式简单分析了jQuery基于ajax的post方法进行文件传输及asp.net后台处理技巧,需要的朋友可以参考下...2016-06-12
- 本文实例讲述了PHP多文件上传类,分享给大家供大家参考。具体如下:<?phpclass Test_Upload{ protected $_uploaded = array(); protected $_destination; protected $_max = 1024000; protected $_messages =...2015-10-30
- 这篇文章主要介绍了js 实现文件上传样式,下面文章举例说明js 是如何实现文件上传样式的,附有代码详细解说,需要的朋友可以参考一下,希望对你有所帮助...2021-10-21
- php 大文件带进度的上传,一直是一个令php程序员很苦恼的问题。查询baidu 、Google ,大体做带进度的上传方式为:flash+php,socket,apc+php等,下面我介绍了apc +php+ajax制作的带进度的上传,并贴出源码,希望对大家有用。 Altern...2015-10-30
- 这篇文章主要为大家详细介绍了C#文件上传的简单实现,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-06-25
- 本文给大家介绍一个不错的需要登录的php 文件上传管理系统,功能简单有需要了解的同学可参考。 代码如下<?php$admin_pw="admin";//管理密码$uploaddir="upload";//上传目录session_start();if($_GET['action']=="g...2015-10-30
asp.net html控件的File控件实现多文件上传实例分享
asp.net中html控件的File控件实现多文件上传简单实例,开发工具vs2010使用c#语言,感兴趣的朋友可以了解下,必定是多文件上传值得学习,或许本文所提供的知识点对你有所帮助...2021-09-22- 这篇文章主要为大家介绍了TypeScript前端上传文件到MinIO示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪...2022-10-12
- 这篇文章主要介绍了JQuery异步提交表单与文件上传功能,结合实例形式分析了jQuery表单提交及文件传输操作的相关实现技巧,需要的朋友可以参考下...2017-01-16
- 复制代码 代码如下:<?php if($_FILES['myfile']['name'] != '') { if($_FILES['myfile']['error'] > 0) { echo "错误状态:" . $_FILES['myfile']['error']; } else { move_uploaded_f...2013-10-04
使用jQuery.form.js/springmvc框架实现文件上传功能
这篇文章主要介绍了使用jQuery.form.jsspringmvc框架实现文件上传功能,非常具有参考借鉴价值,感兴趣的朋友一起学习吧...2016-05-14jquery插件uploadify实现带进度条的文件批量上传
这篇文章主要介绍了jquery插件uploadify实现带进度条的文件批量上传,感兴趣的小伙伴们可以参考一下...2015-12-14- 这篇文章主要介绍了C#简单实现文件上传功能,利用MVC+EF+LigerUI 实现的upload上传功能,感兴趣的小伙伴们可以参考一下...2020-06-25
- 文件上传中有一块非常重要的就是安全验证了,如果验证不合理就很容易给一些人把此利用上传非常的黑客文件了,那么对于新学php新手文件上传验证有多了解呢?如果不懂可以看...2016-11-25