php ajax 无刷新文件上传源码下载
<!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>无刷新文件上传系统</title>
</head>
<body>
<style>
.fu_list {
width:600px;
background:#ebebeb;
font-size:12px;
}
.fu_list td {
padding:5px;
line-height:20px;
background-color:#fff;
}
.fu_list table {
width:100%;
border:1px solid #ebebeb;
}
.fu_list thead td {
background-color:#f4f4f4;
}
.fu_list b {
font-size:14px;
}
/*file容器样式*/
a.files {
width:90px;
height:30px;
overflow:hidden;
display:block;
border:1px solid #BEBEBE;
background:url(img/fu_btn.gif) left top no-repeat;
text-decoration:none;
}
a.files:hover {
background-color:#FFFFEE;
background-position:0 -30px;
}
/*file设为透明,并覆盖整个触发面*/
a.files input {
margin-left:-350px;
font-size:30px;
cursor:pointer;
filter:alpha(opacity=0);
opacity:0;
}
/*取消点击时的虚线框*/
a.files, a.files input {
outline:none;/*ff*/
hide-focus:expression(this.hideFocus=true);/*ie*/
}
</style>
<form id="uploadForm" action="File.php">
<table border="0" cellspacing="1" class="fu_list">
<thead>
<tr>
<td colspan="2"><b>上传文件</b></td>
</tr>
</thead>
<tbody>
<tr>
<td align="right" width="15%" style="line-height:35px;">添加文件:</td>
<td><a href="javascript:void(0);" class="files" id="idFile"></a> <img id="idProcess" style="display:none;" src="img/loading.gif" /></td>
</tr>
<tr>
<td colspan="2"><table border="0" cellspacing="0">
<thead>
<tr>
<td>文件路径</td>
<td width="100"></td>
</tr>
</thead>
<tbody id="idFileList">
</tbody>
</table></td>
</tr>
<tr>
<td colspan="2" style="color:gray">温馨提示:最多可同时上传 <b id="idLimit"></b> 个文件,只允许上传 <b id="idExt"></b> 文件。 </td>
</tr>
<tr>
<td colspan="2" align="center" id="idMsg"><input type="button" value="开始上传" id="idBtnupload" disabled="disabled" />
<input type="button" value="全部取消" id="idBtndel" disabled="disabled" />
</td>
</tr>
</tbody>
</table>
</form>
<script type="text/javascript">
var isIE = (document.all) ? true : false;
var $ = function (id) {
return "string" == typeof id ? document.getElementById(id) : id;
};
var Class = {
create: function() {
return function() {
this.initialize.apply(this, arguments);
}
}
}
var Extend = function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
}
var Bind = function(object, fun) {
return function() {
return fun.apply(object, arguments);
}
}
var Each = function(list, fun){
for (var i = 0, len = list.length; i < len; i++) { fun(list[i], i); }
};
//文件上传类
var FileUpload = Class.create();
FileUpload.prototype = {
//表单对象,文件控件存放空间
initialize: function(form, folder, options) {
this.Form = $(form);//表单
this.Folder = $(folder);//文件控件存放空间
this.Files = [];//文件集合
this.SetOptions(options);
this.FileName = this.options.FileName;
this._FrameName = this.options.FrameName;
this.Limit = this.options.Limit;
this.Distinct = !!this.options.Distinct;
this.ExtIn = this.options.ExtIn;
this.ExtOut = this.options.ExtOut;
this.onIniFile = this.options.onIniFile;
this.onEmpty = this.options.onEmpty;
this.onNotExtIn = this.options.onNotExtIn;
this.onExtOut = this.options.onExtOut;
this.onLimite = this.options.onLimite;
this.onSame = this.options.onSame;
this.onFail = this.options.onFail;
this.onIni = this.options.onIni;
if(!this._FrameName){
//为每个实例创建不同的iframe
this._FrameName = "uploadFrame_" + Math.floor(Math.random() * 1000);
//ie不能修改iframe的name
var oFrame = isIE ? document.createElement("<iframe name="" + this._FrameName + "">") : document.createElement("iframe");
//为ff设置name
oFrame.name = this._FrameName;
oFrame.style.display = "none";
//在ie文档未加载完用appendChild会报错
document.body.insertBefore(oFrame, document.body.childNodes[0]);
}
//设置form属性,关键是target要指向iframe
this.Form.target = this._FrameName;
this.Form.method = "post";
//注意ie的form没有enctype属性,要用encoding
this.Form.encoding = "multipart/form-data";
//整理一次
this.Ini();
},
//设置默认属性
SetOptions: function(options) {
this.options = {//默认值
FileName: "Files[]",//文件上传控件的name,配合后台使用
FrameName: "",//iframe的name,要自定义iframe的话这里设置name
onIniFile: function(){},//整理文件时执行(其中参数是file对象)
onEmpty: function(){},//文件空值时执行
Limit: 10,//文件数限制,0为不限制
onLimite: function(){},//超过文件数限制时执行
Distinct: true,//是否不允许相同文件
onSame: function(){},//有相同文件时执行
ExtIn: ["gif","jpg","rar","zip","iso","swf","exe"],//允许后缀名
onNotExtIn: function(){},//不是允许后缀名时执行
ExtOut: [],//禁止后缀名,当设置了ExtIn则ExtOut无效
onExtOut: function(){},//是禁止后缀名时执行
onFail: function(){},//文件不通过检测时执行(其中参数是file对象)
onIni: function(){}//重置时执行
};
Extend(this.options, options || {});
},
//整理空间
Ini: function() {
//整理文件集合
this.Files = [];
//整理文件空间,把有值的file放入文件集合
Each(this.Folder.getElementsByTagName("input"), Bind(this, function(o){
if(o.type == "file"){ o.value && this.Files.push(o); this.onIniFile(o); }
}))
//插入一个新的file
var file = document.createElement("input");
file.name = this.FileName; file.type = "file"; file.onchange = Bind(this, function(){ this.Check(file); this.Ini(); });
this.Folder.appendChild(file);
//执行附加程序
this.onIni();
},
//检测file对象
Check: function(file) {
//检测变量
var bCheck = true;
//空值、文件数限制、后缀名、相同文件检测
if(!file.value){
bCheck = false; this.onEmpty();
} else if(this.Limit && this.Files.length >= this.Limit){
bCheck = false; this.onLimite();
} else if(!!this.ExtIn.length && !RegExp(".(" + this.ExtIn.join("|") + ")$", "i").test(file.value)){
//检测是否允许后缀名
bCheck = false; this.onNotExtIn();
} else if(!!this.ExtOut.length && RegExp(".(" + this.ExtOut.join("|") + ")$", "i").test(file.value)) {
//检测是否禁止后缀名
bCheck = false; this.onExtOut();
} else if(!!this.Distinct) {
Each(this.Files, function(o){ if(o.value == file.value){ bCheck = false; } })
if(!bCheck){ this.onSame(); }
}
//没有通过检测
!bCheck && this.onFail(file);
},
//删除指定file
Delete: function(file) {
//移除指定file
this.Folder.removeChild(file); this.Ini();
},
//删除全部file
Clear: function() {
//清空文件空间
Each(this.Files, Bind(this, function(o){ this.Folder.removeChild(o); })); this.Ini();
}
}
var fu = new FileUpload("uploadForm", "idFile", { ExtIn: ["gif","jpg"],
onIniFile: function(file){ file.value ? file.style.display = "none" : this.Folder.removeChild(file); },
onEmpty: function(){ alert("请选择一个文件"); },
onLimite: function(){ alert("超过上传限制"); },
onSame: function(){ alert("已经有相同文件"); },
onNotExtIn: function(){ alert("只允许上传" + this.ExtIn.join(",") + "文件"); },
onFail: function(file){ this.Folder.removeChild(file); },
onIni: function(){
//显示文件列表
var arrRows = [];
if(this.Files.length){
var oThis = this;
Each(this.Files, function(o){
var a = document.createElement("a"); a.innerHTML = "取消"; a.href = "javascript:void(0);";
a.onclick = function(){ oThis.Delete(o); return false; };
arrRows.push([o.value, a]);
});
} else { arrRows.push(["<font color='gray'>没有添加文件</font>", " "]); }
AddList(arrRows);
//设置按钮
$("idBtnupload").disabled = $("idBtndel").disabled = this.Files.length <= 0;
}
});
$("idBtnupload").onclick = function(){
//显示文件列表
var arrRows = [];
Each(fu.Files, function(o){ arrRows.push([o.value, " "]); });
AddList(arrRows);
fu.Folder.style.display = "none";
$("idProcess").style.display = "";
$("idMsg").innerHTML = "正在添加文件到您的网盘中,请稍候……<br />有可能因为网络问题,出现程序长时间无响应,请点击“<a href='?'><font color='red'>取消</font></a>”重新上传文件";
fu.Form.submit();
}
//用来添加文件列表的函数
function AddList(rows){
//根据数组来添加列表
var FileList = $("idFileList"), oFragment = document.createDocumentFragment();
//用文档碎片保存列表
Each(rows, function(cells){
var row = document.createElement("tr");
Each(cells, function(o){
var cell = document.createElement("td");
if(typeof o == "string"){ cell.innerHTML = o; }else{ cell.appendChild(o); }
row.appendChild(cell);
});
oFragment.appendChild(row);
})
//ie的table不支持innerHTML所以这样清空table
while(FileList.hasChildNodes()){ FileList.removeChild(FileList.firstChild); }
FileList.appendChild(oFragment);
}
$("idLimit").innerHTML = fu.Limit;
$("idExt").innerHTML = fu.ExtIn.join(",");
$("idBtndel").onclick = function(){ fu.Clear(); }
//在后台通过window.parent来访问主页面的函数
function Finish(msg){ alert(msg); location.href = location.href; }
</script>
</body>
</html>
file.php文件上传的php源码。
<!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>无标题文档</title>
</head>
<body>
<?
$sort=12;
$f_type=strtolower("swf,jpg,rar,zip,7z,iso,gif");//设置可上传的文件类型
$file_size_max=200*1024*1024;//限制单个文件上传最大容量
$overwrite = 0;//是否允许覆盖相同文件,1:允许,0:不允许
$f_input="Files";//设置上传域名称
foreach($_FILES[$f_input]["error"] as $key => $error){
$up_error="no";
if ($error == UPLOAD_ERR_OK){
$f_name=$_FILES[$f_input]['name'][$key];//获取上传源文件名
$uploadfile=$uploaddir.strtolower(basename($f_name));
$tmp_type=substr(strrchr($f_name,"."),1);//获取文件扩展名
$tmp_type=strtolower($tmp_type);
if(!stristr($f_type,$tmp_type)){
echo "<script>alert('对不起,不能上传".$tmp_type."格式文件, ".$f_name." 文件上传失败!')</script>";
$up_error="yes";
}
if ($_FILES[$f_input]['size'][$key]>$file_size_max) {
echo "<script>alert('对不起,你上传的文件 ".$f_name." 容量为".round($_FILES[$f_input]
['size'][$key]/1024)."Kb,大于规定的".($file_size_max/1024)."Kb,上传失败!')</script>";
$up_error="yes";
}
if (file_exists($uploadfile)&&!$overwrite){
echo "<script>alert('对不起,文件 ".$f_name." 已经存在,上传失败!')</script>";
$up_error="yes";
}
$string = 'abcdefghijklmnopgrstuvwxyz0123456789';
$rand = '';
for ($x=0;$x<12;$x++)
$rand .= substr($string,mt_rand(0,strlen($string)-1),1);
$t=date("ymdHis").substr($gettime[0],2,6).$rand;
$attdir="./file/";
if(!is_dir($attdir))
{ mkdir($attdir);}
$uploadfile=$attdir.$t.".".$tmp_type;
if(($up_error!="yes") and (move_uploaded_file($_FILES[$f_input]['tmp_name']
[$key], $uploadfile))){
$_msg=$_msg.$f_name.'上传成功n';
}
else{
$_msg=$_msg.$f_name.'上传失败n';
}
}
}
echo "<script>window.parent.Finish('".$_msg."');</script>";
?>
</body>
</html>
效果图
<?php
if(function_exists('date_default_timezone_set')){
date_default_timezone_set('Asia/Shanghai'); //设定时区
}
define("APP_ROOT",dirname(dirname(__FILE__))); //网站根目录
function visitorIP(){ //访问者IP
if($_SERVER['HTTP_X_FORWARDED_FOR']){
$ipa = $_SERVER['HTTP_X_FORWARDED_FOR'];
}elseif($_SERVER['HTTP_CLIENT_IP']){
$ipa = $_SERVER['HTTP_CLIENT_IP'];
}else{
$ipa = $_SERVER['REMOTE_ADDR'];
}
return $ipa;
}
function cleanDomain($q,$w=0){ //整理域名 $w=1过滤www.前缀 $w=0不过滤
$q = htmlspecialchars(strtolower(trim($q)));
if(substr($q,0,7) == "http://" || substr($q,0,8) == "https://" || substr($q,0,6) == "ftp://"){
$q = str_replace("http:/","",$q);
$q = str_replace("https:/","",$q);
$q = str_replace("ftp:/","",$q);
}
if(substr($q,0,4) == "www." && $w==1) {
$q = str_replace("www.","",$q);
}
$q = trim($q,"/");
return $q;
}
//获取网页
class HTTPRequest
{
/*
获取网页
*/
var $_fp; // HTTP socket
var $_url; // full URL
var $_host; // HTTP host
var $_protocol; // protocol (HTTP/HTTPS)
var $_uri; // request URI
var $_port; // port
// scan url
function _scan_url()
{
$req = $this->_url;
$pos = strpos($req, '://');
$this->_protocol = strtolower(substr($req, 0, $pos));
$req = substr($req, $pos+3);
$pos = strpos($req, '/');
if($pos === false)
$pos = strlen($req);
$host = substr($req, 0, $pos);
if(strpos($host, ':') !== false)
{
list($this->_host, $this->_port) = explode(':', $host);
}
else
{
$this->_host = $host;
$this->_port = ($this->_protocol == 'https') ? 443 : 80;
}
$this->_uri = substr($req, $pos);
if($this->_uri == '')
$this->_uri = '/';
}
// constructor
function HTTPRequest($url)
{
$this->_url = $url;
$this->_scan_url();
}
// download URL to string
function DownloadToString()
{
$crlf = "rn";
$response="";
// generate request
$req = 'GET ' . $this->_uri . ' HTTP/1.0' . $crlf
. 'Host: ' . $this->_host . $crlf
. $crlf;
// fetch
$this->_fp = @fsockopen(($this->_protocol == 'https' ? 'ssl://' : '') . $this->_host, $this->_port);
@fwrite($this->_fp, $req);
while(is_resource($this->_fp) && $this->_fp && !feof($this->_fp))
$response .= fread($this->_fp, 1024);
@fclose($this->_fp);
// split header and body
$pos = strpos($response, $crlf . $crlf);
if($pos === false)
return($response);
$header = substr($response, 0, $pos);
$body = substr($response, $pos + 2 * strlen($crlf));
// parse headers
$headers = array();
$lines = explode($crlf, $header);
foreach($lines as $line)
if(($pos = strpos($line, ':')) !== false)
$headers[strtolower(trim(substr($line, 0, $pos)))] = trim(substr($line, $pos+1));
// redirection?
if(isset($headers['location']))
{
$http = new HTTPRequest($headers['location']);
return($http->DownloadToString($http));
}
else
{
return($body);
}
}
}
function get_html($siteurl) {
//将网页代码存入字符串
$r=new HTTPRequest($siteurl);
$htm=$r->DownloadToString();
return $htm;
}
$visitorip = visitorIP();
$q = cleanDomain($_POST['q']);
$q_encode = urlencode($q);
$title = "同IP站点查询";
$chaxun_status = 0; //查询状态 -1是没有查询参数,0是查询出错,1是查域名,2是查IP
if(isset($_GET['action']) && trim($_GET['action']) == "do"){ //AJAX调出数据
$ipArr = ReverseIP($q);
if(count($ipArr)>0){
echo '<p class="f14">在此IP找到了'.count($ipArr).'个域名,见下:</p>';
echo '<ul class="lst">';
for($i=0;$i<count($ipArr);$i++){
echo '<li><a href="http://'.$ipArr[$i].'/" title="访问 '.$ipArr[$i].'" target="_blank" class="f14 l200">'.$ipArr[$i].'</a></li>';
}
echo '</ul><div class="cboth"></div>';
}else{
echo '<p class="f14">没有找到IP '.$ip.' 对应的域名记录!</p>';
}
die();
}
function IpToInt($Ip){ //IP转为数字
$array=explode('.',$Ip);
$Int=($array[0] * 256*256*256) + ($array[1]*256*256) + ($array[2]*256) + $array[3];
return $Int;
}
function ReverseIP($q){
$htm = get_html('http://www.ip-adress.com/reverse_ip/'.$q);
preg_match_all('/<a href="/whois/(.*)">Whois</a>/', $htm, $tt);
$res = $tt[1];
return $res;
}
if(preg_match("/[a-zA-Z-_]+/si",$q)){ //如果查询的是域名
$ip = gethostbyname($q);
if($ip == $q){
$ip = $visitorip;
$chaxun_status = -1;
}else{
$chaxun_status = 1;
}
}elseif(ereg("^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$",$q)){ //如果查询的是IP
$ip = $q;
$chaxun_status = 2;
}else{
$ip = $visitorip;
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>同IP站点查询</title>
<style>
*{margin:0;padding:0;}
body{font-size:12px;font-family: Geneva, Arial, Helvetica, sans-serif;}
a img {border:0;}
.red{color:#f00;}
.center{text-align:center;}
p{padding:5px 0 6px 0;word-break:break-all;word-wrap:break-word;}
.f14{font-size:14px;}
a,a:visited{color:#0353ce;}
table {font-size:12px;}
table th {font-size:12px;font-weight:bold;background-color:#f7f7f7;line-height:200%;padding: 0 5px;}
table th {font-size:12px;font-weight:bold;background:#EDF7FF;padding: 0 5px;color:#014198;line-height:200%;}
.red{color:red}
.blue{color:blue}
#footer{line-height:150%;text-align:center;color:#9c9c9c;padding: 8px 0;}
#footer a,#footer a:visited{color:#9c9c9c;}
ul.lst{padding:0;margin:0;width:100%;}
ul.lst li{list-style-type:none;float:left;padding:0 0 0 12px;line-height:24px;height:24px;overflow:hidden;}
ul.lst li{width:258px!important;width:270px;}
</style>
<? if($chaxun_status>0){ ?>
<SCRIPT type="text/javascript">
<!--
var xmlHttp;
function creatXMLHttpRequest() {
if(window.ActiveXObject) {
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
} else if(window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}
function startRequest() {
var queryString;
var domain = "<?=$ip?>";
queryString = "q=" + domain;
creatXMLHttpRequest();
xmlHttp.open("POST","./?action=do","true");
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
xmlHttp.send(queryString);
}
function handleStateChange() {
if(xmlHttp.readyState == 1) {
document.getElementById('ipresult').style.cssText = "";
document.getElementById('ipresult').innerHTML = '<span class="green">结果加载中,请稍等...</span>';
}
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
document.getElementById('ipresult').style.cssText = "";
var allcon = xmlHttp.responseText;
document.getElementById('ipresult').innerHTML = allcon;
}
}
}
//-->
</SCRIPT>
<? } ?>
</head>
<body>
<div align="center">
<table cellspacing="4" cellpadding="0" style="background-color:#f7f7f7;border-bottom:1px solid #dfdfdf;" width="778">
<tr>
<td align="left"><a href="/" target="_blank">站长工具</a> > <a href="./" target="_blank">同IP站点查询</a></td>
<td align="right"><a href="javascript:;" onClick="window.external.AddFavorite(document.location.href,document.title);">收藏本页</a></td></tr></table>
<div id="result"><br />
<table width="700" cellpadding="2" cellspacing="0" style="border:1px solid #B2D0EA;">
<tr>
<th align="left"><a href="./" target="_blank">同IP站点查询</a></th>
</tr>
<tr><td align="center">
<table border="0" cellPadding="0" cellSpacing="1">
<tr><td style="font-size:14px">
<br />
<form action="" method="post" name="f1">IP地址或域名 <input name="q" id="q" type="text" size="18" delay="0" value="<? if($chaxun_status>0) echo $q; ?>" style="width:200px;height:22px;font-size:16px;font-family: Geneva, Arial, Helvetica, sans-serif;" /> <input type="submit" value=" 查询 " /></form>
</td></tr></table><br />
</td></tr>
<tr><td align="center" valign="middle" height="40" style="font-size:12px">输入域名或者IP地址,查询同一IP地址的服务器上有哪些网站。</td></tr>
</table>
<br />
<table width="700" cellpadding=2 cellspacing=0 style="border:1px solid #B2D0EA;">
<tr>
<th align="left"><?
if($chaxun_status==1){
echo '<a href="./">'.$title.'</a> > 域名: '.$q;
}elseif($chaxun_status==2){
echo '<a href="./">'.$title.'</a> > IP: '.$ip;
}else{
echo $title;
}
?></th>
</tr>
<tr><td align="left">
<div style="padding:20px">
<p class="f14">
<?
if(!$q){
$ipq = '您的IP地址是:<span class="blue f14">'.$ip.'</span>';
}elseif($chaxun_status == 0){
$ipq = '<b class="red f14">出错啦!</b>没有找到与 <b class="blue f14">'.$q.'</b> 匹配的结果,请确定IP/域名的格式是否写对!</p><p class="f14 blue">你的IP地址是:'.$ip;
}elseif($chaxun_status==1){
$ipq = '你查询的域名 <span class="blue f14">'.$q.'</span></p><p class="f14">域名的IP: <span class="blue f14">'.$ip.'</span>';
}else{
$ipq = "你查询的IP:".$ip;
}
echo $ipq;
?></p><? if($chaxun_status>0){ ?>
<div id="ipresult"></div><script>startRequest();</script>
<? } ?></p><hr style="border-style: dotted;" color="#cccccc" size="1" /><p align="center">相关查询: <A href="../alexa">Alexa查询</A> | <A href="../domain/">域名注册查询</A> | <A href="../whois">Whois查询</A> | <A href="../ip/">IP地址查询</A> | <A href="../pr/pr.php">PR查询</A> | <A href="../weath/">天气预报查询</A> | <A href="../robot">模仿蜘蛛</A> | <A href="/index.php">友情链接查询</A></p>
</div>
</td></tr>
</table><br />
</div>
</div>
<div id="footer">© 2009 <a href="http://tool.111cn.net/">站长工具</a></div>
<div style="display:none;"></div>
</body>
</html>
同IP查询代码下载包
本文章是利用了php的fso功能读取模板文件,然后根据我处自定义好的标签进行了文件模板替换就OK了。function GetContent($type){
if( $type )
{
if(file_exists('./mail_room.html') )
{
$content = file_get_contents( './mail_room.html');
}
else
{
ShowMsg('file can' read fail ');
}
}
else
{
if( file_exists( './mail_person.html') )
{
$content = file_get_contents( './mail_person.html');
}
else
{
ShowMsg('person file read fail!');
}
}
return $content;
}
function template($str)
{
$_url = $_SERVER['HTTP_HOST'];
$_temp = str_replace('{username}',$_SESSION['uname'],$str);
$_temp = str_replace('[bgpic]',getPic(),$_temp);
$_temp = str_replace('{url}',$_url,$_temp);
return $_temp;
}
我们来看看模板文件
<style type="text/css">
#mail{
font-family:"微软雅黑", "宋体",arial;
font-size:12px;
height:530px;
width:662px;
background:url(http://111cn.net/emailimages/mailback.jpg) no-repeat top left;
}
#photo{
height:380px;
width:630px;
position:absolute;
top:20px;
left:25px;
background:url([bgpic]) no-repeat top left;
}
#photo img{
border:none;
height:380px;
width:630px;
}
#infomation{
padding:5px 0 0 0;
position:absolute;
top:400px;
left:25px;
height:105px;
width:629px;
}
#entry{
margin:10px 0 0 6px;
float:left;
width:108px;
height:90px;
}
#entry ul{
margin: 0;
padding: 0;
}
#entry li{
float:left;
list-style:none;
text-indent:10px;
}
#entry a{
display:block;
height:42px;
width:53px;
}
#cjhd{
background:url(http://111cn.net/emailimages/cjhd.gif) no-repeat top left;
height:42px;
width:53px;
}
#aygw{
background:url(http://111cn.net/emailimages/aygw.gif) no-repeat top left;
height:42px;
width:53px;
}
#zdzx{
background:url(http://111cn.net/emailimages/zdzx.gif) no-repeat top left;
height:42px;
width:53px;
}
#title{
height:21px;
margin:5px 0;
background:url(http://111cn.net/emailimages/title.gif) no-repeat top left;
}
#artical{
margin:0 0 0 5px;
float:left;
width:180px;
height:105px;
overflow:hidden;
}
#words{
font-size:14px;
height:70px;
line-height:18px;
margin:20px 0 0 0;
}
#words p{
margin:0;
padding:0;
}
#words a{
text-decoration:underline;
color:#be2f60;
}
#artical{
margin:5px 0 0 0px;
}
#artical ul{
padding:0;
margin:5px 0 0 5px;
}
#artical ul li{
list-style:none;
background:url(111cn.net/emailimages//emailimages/dot.gif) no-repeat 0px 7px;
text-indent:10px;
height:18px;
color:#505050;
float:left;
width:180px;
}
#artical ul li a{
text-decoration:none;
color:#5e5e5e;
}
</style>
</head>
<body>
<div id="mail">
<div id="photo"> </div>
<div id="infomation">
<div id="entry">
<ul>
<li id="cjhd"><a href="#"></a></li>
<li id="zdzx"><a href="#"></a></li>
<li id="aygw"><a href="#"></a></li>
</ul>
</div>
<div id="artical">
<div id="title">
</div>
<ul>
<li><a href="#">新潮食物与儿童疾病的关系 </a></li>
<li><a href="#">不宜喂养宝宝的24种食物 </a></li>
<li><a href="#">育儿饮食错误观点大罗列</a></li>
</ul>
</div>
<div id="words">
<p>{username}说:</p>
<p style="text-indent:20px;"><a href="http://{url}">我发现明星宝宝啦,<br/> 快来一起合影吧!</a></p>
</div>
</div>
</div>
<!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>google分页</title>
<meta name="keywords" content="仿google php分页程序 " />
<meta name="description" content="仿google php分页程序" />
<style type="text/css">
<!--
body { font-family: Arial, Helvetica, sans-serif; font-size: 12px; margin: 0px; padding: 0px; }
div { height: auto; width: 800px; margin: 10px auto; line-height:20px; }
/*CSS manu style pagination*/
.manu {
PADDING-RIGHT: 3px; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; MARGIN: 3px; PADDING-TOP: 3px; TEXT-ALIGN: center
}
.manu A {
BORDER-RIGHT: #eee 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #eee 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #eee 1px solid; COLOR: #036cb4; PADDING-TOP: 2px; BORDER-BOTTOM: #eee 1px solid; TEXT-DECORATION: none
}
.manu A:hover {
BORDER-RIGHT: #999 1px solid; BORDER-TOP: #999 1px solid; BORDER-LEFT: #999 1px solid; COLOR: #666; BORDER-BOTTOM: #999 1px solid
}
.manu A:active {
BORDER-RIGHT: #999 1px solid; BORDER-TOP: #999 1px solid; BORDER-LEFT: #999 1px solid; COLOR: #666; BORDER-BOTTOM: #999 1px solid
}
.manu .current {
BORDER-RIGHT: #036cb4 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #036cb4 1px solid; PADDING-LEFT: 5px; FONT-WEIGHT: bold; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #036cb4 1px solid; COLOR: #fff; PADDING-TOP: 2px; BORDER-BOTTOM: #036cb4 1px solid; BACKGROUND-COLOR: #036cb4
}
.manu .disabled {
BORDER-RIGHT: #eee 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #eee 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #eee 1px solid; COLOR: #ddd; PADDING-TOP: 2px; BORDER-BOTTOM: #eee 1px solid
}
-->
</style>
</head>
<body>
<?php
require('web_page.php'); //包含分页程序
//数据库配置
$mysql_host = 'localhost'; //数据库服务器
$mysql_user = 'root'; //数据库用户名
$mysql_pass = '123456'; //数据库密码
$mysql_db = 'test'; //数据库名
//连接mysql数据库
$link = mysql_connect($mysql_host,$mysql_user,$mysql_pass) or die ('连接MYSQL服务器出错');
mysql_select_db($mysql_db,$link) or die ('连接MYSQL数据库出错');
//分页开始
$sql_page = "select news_id,news_title from cms_news order by news_id desc";
$sql = mysql_query($sql_page);
$num = mysql_num_rows($sql); //总条数
$max = 1; //每页条数
$pagenum = ceil($num/$max); //可分页数
if(!isset($_GET['page']) or !intval($_GET['page']) or !is_numeric($_GET['page']) or $_GET['page'] > $pagenum){
$page = 1; //当页数不存在 不为十进制数 不是数字 大于可分页数 为1
}else{
$page = $_GET['page']; //当前页数
}
$min = ($page-1)*$max; //当前页从$min条开始
$sql = "{$sql_page} limit $min,$max";
echo '<div>';
if($num){
$sql = mysql_query($sql);
for(;$row = mysql_fetch_array($sql);){
echo '<li><a href="show.php?id='.$row['news_id'].'">'.$row['news_title'].'</a></li>';
}
}else{
echo '<li>暂无</li>';
}
echo '</div>';
//mysql_free_result($sql); //释放资源
?>
<div class="manu"><?php web_page(""); //调用输出分页,引用你的页面其他参数 如:web_page("&class=2&news=6") ?></div>
<?php
//分页结束
mysql_close();
?>
</body>
</html>
上面为调用方法下面为分页程序
<?php
function web_page($pageurl="", $pageselect = true){
global $page,$num,$pagenum; //当前页数 总页数 可分页数
echo "共 $num 条记录,";
$uppage = $page - 1; //上一页
$downpage = $page + 1; //下一页
$lr = 5; //显示多少个页数连接
$left = floor(($lr-1)/2); //左显示多少个页数连接
$right = floor($lr/2); //右显示多少个页数连接
//下面求开始页和结束页
if($page <= $left){ //如果当前页左不足以显示页数
$leftpage = 1;
$rightpage = (($lr<$pagenum)?$lr:$pagenum);
}elseif(($pagenum-$page) < $right){ //如果当前页右不足以显示页数
$leftpage = (($pagenum<$lr)?1:($pagenum-$lr+1));
$rightpage = $pagenum;
}else{ //左右可以显示页数
$leftpage = $page - $left;
$rightpage = $page + $right;
}
//前$lr页和后$lr页
$qianpage = (($page-$lr) < 1?1:($page-$lr));
$houpage = (($page+$lr) > $pagenum?$pagenum:($page+$lr));
//输出分页
if($page != 1){
echo "<a title="首页" href="".$_SERVER['PHP_SELF']."?$pageurl"><<</a> <a title="上一页" href="".$_SERVER['PHP_SELF']."?page=$uppage$pageurl"><</a> ";
}else{
echo "<span class='disabled'><<</span><span class='disabled'><</span> ";
}
for($pages = $leftpage; $pages <= $rightpage; $pages++){
if($pages == $page){
echo "<span class='current'>$pages</span> ";
}else{
echo "<a href="?page=$pages$pageurl">$pages</a> ";
}
}
if($page != $pagenum){
echo "<a title="下一页" href="".$_SERVER['PHP_SELF']."?page=$downpage$pageurl">></a> <a title="末页" href="".$_SERVER['PHP_SELF']."?page=$pagenum$pageurl">>></a>";
}else{
echo "<span class='disabled'>></span><span class='disabled'> >></span> ";
}
//跳转
$javapage = <<<EOM
<script language="javascript">
function web_page(targ,selObj,restore){
eval("self"+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
</script>
EOM;
echo $javapage;
if ($pageselect){
echo "跳转至 <select onchange="web_page('parent',this,0)" name="menu1">";
for($pages = 1; $pages <= $pagenum; $pages++){
$selected = ($pages == $page)?" selected="selected"":"";
echo "<option value="".$_SERVER['PHP_SELF']."?page=$pages$pageurl"$selected> $pages</option>";
}
echo "</select> 页";
}
}
?>
从中文到英语
class Google_API_translator {
public $out = "";
function translate() {
$this->out = "";
$text = urlencode("计算机");//要翻译的单词
$google_translator_url = "http://translate.google.com/translate_a/t?client=t&text=".$text."&sl=zh_CN&tl=en";
echo $google_translator_url;
$gphtml = $this->postPage(array("url" => $google_translator_url));
$this->out = $gphtml;
return $this->out;
}
function postPage($opts) {
$html = "";
if($opts["url"] != "") {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $opts["url"]);
$html = curl_exec($ch);
if(curl_errno($ch)) $html = "";
curl_close ($ch);
}
return $html;
}
}
$g = new Google_API_translator();
$g->translate();
从英语到中文
class Google_API_translator {
public $out = "";
function translate() {
$this->out = "";
$text = urlencode("computer");//要翻译的单词
$google_translator_url = "http://translate.google.com/translate_a/t?client=t&text=".$text."&sl=en&tl=zh_CN";
//拼凑google翻译的api url
$gphtml = $this->postPage(array("url" => $google_translator_url));
$this->out = $gphtml;
return $this->out;
}
function postPage($opts) {
$html = "";
if($opts["url"] != "") {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $opts["url"]);
$html = curl_exec($ch);
if(curl_errno($ch)) $html = "";
curl_close ($ch);
}
return $html;
}
}
$g = new Google_API_translator();
$g->translate();
很完美,返回的结果中没有任何编码问题。从google返回的中文编码完全正确。
相关文章
php无刷新利用iframe实现页面无刷新上传文件(1/2)
利用form表单的target属性和iframe 一、上传文件的一个php教程方法。 该方法接受一个$file参数,该参数为从客户端获取的$_files变量,返回重新命名后的文件名,如果上传失...2016-11-25- 本文章来人大家介绍一个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
jQuery+PHP发布的内容进行无刷新分页(Fckeditor)
这篇文章将使用jQuery,并结合PHP,将Fckeditor发布的内容进行分页,并且实现无刷新切换页面。 本文假设你是WEB开发人员,掌握了jQuery和PHP相关知识,并且熟知Fckeditor的配置和使用。...2015-10-23- 本篇文章主要说明的是与php文件上传的相关配置的知识点。PHP文件上传功能配置主要涉及php.ini配置文件中的upload_tmp_dir、upload_max_filesize、post_max_size等选项,下面一一说明。打开php.ini配置文件找到File Upl...2015-10-21
- 这篇文章主要介绍了解决vue刷新页面以后丢失store的数据问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-08-12
- 这篇文章主要介绍了解决vuex数据页面刷新后初始化操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-07-26
- 这篇文章主要介绍了java后台实现js关闭本页面,父页面指定跳转或刷新操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-11-16
借助FileReader实现将文件编码为Base64后通过AJAX上传
这篇文章主要介绍了借助FileReader实现将文件编码为Base64后通过AJAX上传的方法,包括后端对文件数据解码并保存的PHP代码,需要的朋友可以参考下...2015-12-25- 本文就是和大家分享一款由php结合ajax实现的无刷新留言板,先给大家看一下最后的效果图:数据库连接代码如下: <?php$conn = @mysql_connect("localhost","root","root") or die ("MySql连接错误");mysql_select_db("d...2015-10-30
- 这篇文章主要介绍了基于jquery实现表格无刷新分页,功能实现了前端排序功能,增加了前端搜索功能,感兴趣的小伙伴们可以参考一下...2016-01-08
- 这篇文章主要为大家详细介绍了js实现上传文件添加和删除文件选择框 ,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2016-10-25
- 这篇文章主要介绍了jQuery+ajax简单实现文件上传的方法,结合实例形式简单分析了jQuery基于ajax的post方法进行文件传输及asp.net后台处理技巧,需要的朋友可以参考下...2016-06-12
- 这篇文章主要介绍了vue实现在进行增删改操作后刷新页面,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-08-05
- 这篇文章主要介绍了Vue 中获取当前时间并实时刷新,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2020-05-13
- 本文实例讲述了PHP多文件上传类,分享给大家供大家参考。具体如下:<?phpclass Test_Upload{ protected $_uploaded = array(); protected $_destination; protected $_max = 1024000; protected $_messages =...2015-10-30
- 这篇文章主要介绍了C#实现刷新桌面的方法,涉及C#基于shell32.dll动态链接库实现系统桌面刷新的技巧,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25
- 这篇文章主要介绍了js 实现文件上传样式,下面文章举例说明js 是如何实现文件上传样式的,附有代码详细解说,需要的朋友可以参考一下,希望对你有所帮助...2021-10-21
- 代码很简单,实现的功能却很实用,直接奉上代码CSS:复制代码 代码如下: <meta charset="utf-8" /> <title>Pull to Refresh</title> <meta name="viewport" content="width=device-width,height=device-height,inital-scal...2015-03-15