分类目录归档:图片/文字
换了一个vps用,以前的到期了
http://thenynocportal.com/aff.php?aff=084
3.95$*12 (不支持月付,全年折合人民币320左右)
5G硬盘 256M内存(使用FREE512MB 优惠码赠送了512m内存 FREE500GB赠送500G的硬盘)500G每月的流量 2个独立ip
安装软件:ubuntu 8.04 nginx+php5+mysql5+postfix
机房位于美国洛杉矶,ping的速度还可以,不过http下载的速度有点慢
《蓝树叶》 联想到现在的网络时代
美术课上,老师教同学们画风景,要画上树、房子和小山。李丽画好了近处的房子、远处的小山。她正要画树,可是绿色铅笔找不到了。
李丽看看旁边的林园园已经把树画好了,树叶那么绿,真惹人爱。李丽小声对林园园说:“把绿铅笔借给我用一用行吗?”林园园吞吞吐吐地说:“我还没有画完 呢。”李丽只好坐在那里看林园园画。等她画完了,李丽说:“现在可以把绿铅笔借给我了吧?”林园园说:“我怕你把笔尖弄断了。”李丽说:“我小心一点儿”
林园园从盒子里拿出绿铅笔,说:“你要注意,不要削,画的时候不要用力,不要画得太多!”李丽连忙说:“我只画树叶和小草。”林园园皱着眉头,说:“还要 画小草吗?”李丽看了看林园园,没有接她的铅笔。李丽拿起自己的蓝铅笔,用心地画着一片片树叶。林园园看见这些蓝树叶,不由得脸红了。
这篇小学时的课文相信大家都很熟悉,反正我一直以来,只要一想到借东西和自私这两样生活中最常见的事物,就想到蓝树叶课文中的借绿色铅笔画树叶,从’借’又想到现在的网络时代,网络时代讲究的是共享,在计算机网络中,大量的各种各样的信息都是无私的人们奉献出来的,总之不管是‘借’还是‘共享’其实都是给予别人方便。
最近一直想用自己的所学做一个网站,现在想好了,网站名称就叫 《蓝树叶》 其主题也是共享信息,给予别人方便的同时,也分享到别人给予的方便!
《快乐分享 分享快乐》
做了个动态qq头像
今天开始写一个通用的企业网站程序
最近要帮我哥的公司做一个企业网站,再加以我叔公司的网站到现在还是半成品就挂到网上了,心中老是过意不去,但是自己都去好好解决一下,最近也有空了,准备花上一周左右的时间,把这两个企业网站做掉。
做完这二个网站后,自己也准备做一个网站自己用了,时间过得真快,还有二个月就快过年了。。。感慨一下
下面是今天用了一下午修改了下自己以前的网站后台ui,后台界面就不重新做了凑合着用了。。
主是把数据库的视图查询部分做了下,然后完善了下框架的路由!
- <?php
- class Model{
- public $db;
- public function __construct()
- {
- $this->db= new PDO(conf(‘dbType’).‘:host=’.conf(‘dbHost’).‘;dbname=’.conf(‘dbName’), conf(‘dbUser’), conf(‘dbPass’));
- $this->db->exec(‘SET NAMES ‘.conf(‘charset’));
- }
- function query($sql)
- {
- $rs = $this->db->query($sql);
- return $rs;
- }
- function beginTransaction()
- {
- return $this->db->beginTransaction();
- }
- function commit()
- {
- return $this->db->commit();
- }
- function rollBack()
- {
- return $this->db->rollBack();
- }
- function exec($sql)
- {
- return $this->db->exec($sql);
- }
- function lastInsertId()
- {
- return $this->db->lastInsertId();
- }
- function setAttribute($attr, $value)
- {
- return $this->db->setAttribute($attr, $value);
- }
- function insert($table,$data)
- {
- $table=conf(‘dbprefix’).$table;
- $fields = "";
- $values = "";
- foreach($data as $field=>$value)
- {
- $fields .= "`$field`, ";
- $values .= "’$value’, ";
- }
- $fields = substr_replace($fields, "", -2, 1);
- $values = substr_replace($values, "", -2, 1);
- $sql = "insert into `$table` ($fields) values ($values)";
- //echo $sql;
- $rs = $this->db->query($sql) ;
- return $this->db->lastInsertId();
- }
- function del($table,$keyarr){
- $table=conf(‘dbprefix’).$table;
- $where = "";
- foreach($keyarr as $key=>$key_value)
- {
- $where .= "`$key`=’$key_value’";
- }
- $sql = "delete from `$table` where $where";
- $rs = $this->db->query($sql);
- return $rs;
- }
- function update($table,$data, $keyarr)
- {
- $table=conf(‘dbprefix’).$table;
- $set = "";
- foreach($data as $field=>$value)
- {
- $set .= "`$field`=’$value’, ";
- }
- $set = substr_replace($set, "", -2, 1);
- $where = "";
- foreach($keyarr as $key=>$key_value)
- {
- $where .= "`$key`=’$key_value’";
- }
- $sql = "update `$table` set $set where $where";
- //echo $sql;
- $rs = $this->db->query($sql);
- return $rs;
- }
- function find($table,$where=”,$field=‘*’,$order=”,$group=”)
- {
- $sql=$this->_map($table,$where,$field,$order,”,$group);
- //echo $sql;
- return $this->_find($sql);
- }
- function findAll($table,$where=”,$field=‘*’,$order=”,$limit=”,$group=”)
- {
- $sql=$this->_map($table,$where,$field,$order,$limit,$group);
- return $this->_findAll($sql);
- }
- function count($table,$where=”,$field=‘*’,$order=”,$group=”)
- {
- $sql=$this->_map($table,$where,$field,$order,”,$group);
- return $this->_count($sql);
- }
- function _count($sql)
- {
- $rs=$this->query($sql);
- $count=$rs->fetchColumn();
- $count=emptyempty($count)?0:$count;
- return $count;
- }
- function _find($sql)
- {
- $rs=$this->query($sql);
- $row=$rs->fetch(PDO::FETCH_ASSOC);
- return $row;
- }
- function _findAll($sql)
- {
- $rs=$this->query($sql);
- $row=$rs->fetchall(PDO::FETCH_ASSOC);
- return $row;
- }
- function _map($table,$where=”,$field=‘*’,$order=”,$limit=”,$group=”)
- {
- $order=emptyempty($order)?”:‘order by ‘.$order;
- $limit=emptyempty($group)?”:‘limit ‘.$limit;
- $group=emptyempty($group)?”:‘group by ‘.$group;
- $w=”;
- if(!emptyempty($where)){
- if(is_array($where)){
- $w.=‘where’;
- foreach($where as $k=>$v){
- $w.=" $k=’$v’ and";
- }
- $w=substr($w,0,strlen($w)-3);
- }else{
- $w=$where;
- }
- }
- if(is_array($table)){
- $table1=conf(‘dbprefix’).$table[0];
- //echo $table1;
- $count=count($table);
- $joinleft=”;
- array_shift($table);
- foreach($table as $v){
- foreach($v as $k2=>$v2){
- $k2=conf(‘dbprefix’).$k2;
- foreach($v2 as $k3=>$v3){
- $l="$table1.$k3=$k2.$v3";
- }
- $joinleft.="left join $k2 on $l ";
- }
- }
- $sql="select $field from $table1 $joinleft $w $order $group $limit";
- }else{
- $sql="select $field from $table $w $order $group $limit";
- }
- return $sql;
- }
- }
- //fetch(‘PDO_FETCH_ASSOC’)
- ?>
网站后台界面 调整了部分css,对ff的兼容性更好些
网站的url形式
好久没玩QQ音速了,今天刚玩就全连了一把
简单网站统计功能的实现(PV IP 真实访客数)
主要统计三个数值,网站的pv 和ip 以及真实访客数 因为有详细的统计记录,所以可以实现的功能还有很大的扩展!把tallydate使用内存表的话,速度就会更快了
需要用到二张表
- CREATE TABLE `tally` (
- `date` date NOT NULL,
- `pvtotal` int(10) NOT NULL,
- `iptotal` int(10) NOT NULL,
- `dltotal` int(10) NOT NULL,
- PRIMARY KEY (`date`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
- CREATE TABLE `tallydata` (
- `tdid` int(10) NOT NULL auto_increment,
- `ip` int(10) NOT NULL,
- `cookie` varchar(32) NOT NULL,
- `date` date NOT NULL,
- `time` int(10) NOT NULL,
- `uri` varchar(255) default NULL,
- `referer` varchar(255) default NULL,
- PRIMARY KEY (`tdid`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
统计的调用文件(用于所在统计的页面进行js调入):
(注:因项目使用的是ThinkPHP框架,所以贴出的只是代码片段!因为代码刚完成,所以没有做优化以及注释)
- <?php
- class TallyAction extends Action{
- public function index(){
- if($_SERVER[‘SERVER_NAME’]!=‘fullyee.com’ && $_SERVER[‘SERVER_NAME’]!=‘www.fullyee.com’ && $_SERVER[‘SERVER_NAME’]!=‘company.fullyee.com’) exit;
- $add[‘ip’]=ip2long(get_client_ip());
- if(!Cookie::is_set(‘fullyeetally’)){
- $value=md5(microtime().$add[‘ip’].rand());
- $overTime=mktime(0,0,0,date(‘m’),date(‘d’)+1,date(‘Y’))-time();
- Cookie::set("fullyeetally",$value,time()+$overTime);
- }
- $fullyeetally=Cookie::get(‘fullyeetally’);
- $add[‘cookie’]=$fullyeetally;
- $add[‘date’]=date(‘Y-m-d’);
- $add[‘time’]=time();
- $add[‘uri’]=$_SERVER[‘SERVER_NAME’].$_SERVER[‘REQUEST_URI’];
- $add[‘referer’]=$_SERVER[‘HTTP_REFERER’];
- $tallydata_=D(‘Tallydata’);
- $tallydata_->create($add);
- $tallydata_->add();
- }
- public function saveData()
- {
- $tally_=D(‘Tally’);
- $tallydata_=D(‘Tallydata’);
- $nowDate=date(‘Y-m-d’,time()-3600*24);
- $now[‘date’]=$nowDate;
- $now[‘iptotal’]=$this->gototal($nowDate,‘ip’);
- $now[‘pvtotal’]=$tallydata_->count(array(‘date’=>$nowDate),‘tdid’);
- $now[‘dltotal’]=$this->gototal($nowDate,‘cookie’);
- if($tally=$tally_->find(array(‘date’=>$nowDate))){
- $tally_->save(array(‘iptotal’=>$now[‘iptotal’],‘pvtotal’=>$now[‘pvtotal’],‘dltotal’=>$now[‘dltotal’]),array(‘date’=>$nowDate));
- }else{
- $tally_->create($now);
- $tally_->add();
- }
- $timeDel=time()-3600*24*50;
- $tallydata_->query("delete from `tallydate` where `time`<$timeDel");
- echo ‘Success ‘+date(‘Y-m-d H:i:s’);
- }
- function gototal($nowDate,$a)
- {
- $tallydata_=D(‘Tallydata’);
- $now[‘iptotal’]=$tallydata_->query("select count(distinct $a) from `tallydata` where `date`=’$nowDate’ ");
- return $now[‘iptotal’][0]["count(distinct $a)"];
- }
- }
- ?>
程序中的 saveDate 部分,用于服务器的定时运行,最简单的方法就是用linux的crontab在一个访问人数比较少的时间wget一下saveDate代码就行了。。这段代码的作用是,把前一天的访问数据全部统计,以天为单位写入tally表!并且删除一定时间外的统计记录。默认是删除50天以前的全部统计记录
显示部分:
- <?php
- class configAction extends Action{
- function _initialize(){
- header("Content-Type:text/html; charset=utf-8");
- }
- public function tally()
- {
- $tally_=D(‘Tally’);
- $tallydata_=D(‘Tallydata’);
- $nowDate=date(‘Y-m-d’);
- $now[‘date’]=$nowDate;
- $now[‘iptotal’]=$this->gototal($nowDate,‘ip’);
- $now[‘pvtotal’]=$tallydata_->count(array(‘date’=>$nowDate),‘tdid’);
- $now[‘dltotal’]=$this->gototal($nowDate,‘cookie’);
- if($tally=$tally_->find(array(‘date’=>$nowDate))){
- $tally_->save(array(‘iptotal’=>$now[‘iptotal’],‘pvtotal’=>$now[‘pvtotal’],‘dltotal’=>$now[‘dltotal’]),array(‘date’=>$nowDate));
- }else{
- $tally_->create($now);
- $tally_->add();
- }
- $today[‘pv’]=$now[‘pvtotal’];
- $today[‘ip’]=$now[‘iptotal’];
- $today[‘dl’]=$now[‘dltotal’];
- $yesterdayDate=date(‘Y-m-d’,time()-3600*24);
- //echo $yesterdayDate;
- $yesterday=$tally_->find(array(‘date’=>$yesterdayDate));
- //dump($yesterday);
- $yesterday[‘pv’]=isset($yesterday[‘pvtotal’])?$yesterday[‘pvtotal’]:‘0’;
- $yesterday[‘ip’]=isset($yesterday[‘iptotal’])?$yesterday[‘iptotal’]:‘0’;
- $yesterday[‘dl’]=isset($yesterday[‘dltotal’])?$yesterday[‘dltotal’]:‘0’;
- $maxpv=$this->gomax(‘pvtotal’);
- $maxip=$this->gomax(‘iptotal’);
- $maxdl=$this->gomax(‘dltotal’);
- $max[‘pv’]=$maxpv[‘pvtotal’];
- $max[‘pvdate’]=$maxpv[‘date’];
- $max[‘ip’]=$maxip[‘iptotal’];
- $max[‘ipdate’]=$maxip[‘date’];
- $max[‘dl’]=$maxdl[‘dltotal’];
- $max[‘dldate’]=$maxdl[‘date’];
- $this->assign(‘today’,$today);
- $this->assign(‘yesterday’,$yesterday);
- $this->assign(‘max’,$max);
- $this->assign(‘nowtime’,date(‘Y年m月d日 H:i:s’));
- $this->display();
- }
- function gomax($a)
- {
- $tally_=D(‘Tally’);
- $max=$tally_->query("select * from `tally` order by `$a` desc limit 1");
- return $max[0];
- }
- function gototal($nowDate,$a)
- {
- $tallydata_=D(‘Tallydata’);
- $now[‘iptotal’]=$tallydata_->query("select count(distinct $a) from `tallydata` where `date`=’$nowDate’ ");
- return $now[‘iptotal’][0]["count(distinct $a)"];
- }
- }
- ?>
jquery使用Jcrop插件轻松实现上传图片后选取区域做头像
jquery使用Jcrop插件轻松实现上传图片后选取区域做头像
一般网站上传头像部分会比较麻烦,如果完全程序控制的话,程序把上传的图片自动裁切成指定大小的头像的话,很有可能会破坏头像的整体美观。所以现在大多数web2.0网站都有用js或flash来实现头像的上传与选取!
现在用jquery加上jcrop插件的话,就可以非常简单的实现这些功能!如果再加上编写的一些ajax处理部分的话就基本上可以满足一般web2.0的使用要求了
- <?php
- if($_GET[‘act’]==‘saveThumb’){
- $targ_w = $targ_h = 150;
- $jpeg_quality = 100;
- $src = $_POST[‘bigImage’];
- $img_r = imagecreatefromjpeg($src);
- $dst_r = ImageCreateTrueColor( $targ_w, $targ_h );
- imagecopyresampled($dst_r,$img_r,0,0,$_POST[‘x’],$_POST[‘y’],$targ_w,$targ_h,$_POST[‘w’],$_POST[‘h’]);
- header(‘Content-type: image/jpeg’);
- imagejpeg($dst_r,null,$jpeg_quality);
- exit;
- }
- ?>
- <html>
- <head>
- <script src="jquery.pack.js"></script>
- <script src="jquery.Jcrop.pack.js"></script>
- <link rel="stylesheet" href="jquery.Jcrop.css" type="text/css" />
- <script language="Javascript">
- $(function(){
- });
- function goss(){
- jQuery(‘#cropbox’).Jcrop({
- onChange: showPreview,
- onSelect: showPreview,
- onSelect: updateCoords,
- aspectRatio: 1
- });
- }
- function updateCoords(c)
- {
- $(‘#x’).val(c.x);
- $(‘#y’).val(c.y);
- $(‘#w’).val(c.w);
- $(‘#h’).val(c.h);
- };
- function checkCoords()
- {
- if ($(‘#x’).val()==”){
- alert(‘请先上传头像然后选择裁切头像最后进行保存!’);
- return false;
- }
- };
- function showPreview(coords)
- {
- var rx = 150 / coords.w;
- var ry = 150 / coords.h;
- var w2=$("#bigwidth").val();
- var h2=$("#bigheight").val();
- jQuery(‘#preview’).css({
- width: Math.round(rx * w2) + ‘px’,
- height: Math.round(ry * h2) + ‘px’,
- marginLeft: ‘-‘ + Math.round(rx * coords.x) + ‘px’,
- marginTop: ‘-‘ + Math.round(ry * coords.y) + ‘px’
- });
- }
- </script>
- </head>
- <body>
- <?php
- if($_GET[‘act’]==‘upload’){
- if($_POST[‘upload’]==‘upload’){
- $uploaddir =‘upload/’;
- $uploadfile = $uploaddir . basename($_FILES[‘file’][‘name’]);
- //print_r($_FILES[‘file’]);
- //echo $uploadfile;
- if (move_uploaded_file($_FILES[‘file’][‘tmp_name’], $uploadfile)) {
- list($w, $h, $type, $attr)=getimagesize($uploadfile);
- $str=”;
- if($w>550){
- $str="width:550px;";
- }
- if($h>550){
- $str.=" height:550px;";
- }
- $str=emptyempty($str)?”:"style=’ ".$str." ‘";
- $f1="<img src=’$uploadfile’ border=0 $str id=’cropbox’ >";
- $f2="<img src=’$uploadfile’ border=0 $str id=’preview’ >";
- echo ‘<script language="javascript">parent.$("#showBig").html("’.$f1.‘");parent.$("#showThumb").html("’.$f2.‘");parent.goss();parent.$("#bigwidth").val("’.$w.‘");parent.$("#bigheight").val("’.$h.‘");parent.$("#bigImage").val("’.$uploadfile.‘");</script>’;
- }else {
- echo "<script>alert(‘文件上传失败!’);</script>";
- }
- }
- ?>
- <div style="margin:0px;font-size:12px;">
- <FORM ACTION="?act=upload" METHOD=POST enctype="multipart/form-data">
- <input type="file" name="file" id="file" />
- <input type="submit" name="button" id="button" value="提交" />
- <input name="upload" type="hidden" id="upload" value="upload" /><input type="hidden" name="MAX_FILE_SIZE" value="3000000" />
- </FORM>
- </div>
- <?php
- exit;
- }
- ?>
- <div id="showBig" style="width:500px;height:500px;border:2px solid #E6E0CE;padding:3px;"></div>
- <iframe style="width:500px;height:60px;padding:0px;" src="?act=upload"></iframe>
- <div id="showThumb" style="width:152px;height:152px;border:1px solid #cccccc;padding:1px; overflow: hidden;"></div>
- <div style="margin-top:20px;">
- <form action="?act=saveThumb" method="post" onsubmit="return checkCoords();">
- <input type="hidden" id="bigImage" name="bigImage" />
- <input type="hidden" id="bigwidth" name="bigwidth" />
- <input type="hidden" id="bigheight" name="bigheight" />
- <input type="hidden" id="x" name="x" />
- <input type="hidden" id="y" name="y" />
- <input type="hidden" id="w" name="w" />
- <input type="hidden" id="h" name="h" />
- <input type="submit" value="保存用户头像" />
- </form>
- </div>
- </body>
- </html>
在windows下启用php的mail()函数进行发信
其实要想在windows下使用php的mail()函数进行发信的话,只要机器里安装了smtp就可以了
当然iis有内置的smtp,可是如果web服务器安装的是apache的话总不可能为了一个smtp而再去安装一个iis吧
所以找了个简单的smtp服务器软件(1st SMTP Server)找的是一个老版本的,才700多k,没有其它的无用功能!
先下载好1st SMTP Server后,运行里面的注册机,再运行主程序,进行注册。注册完了后就可以关闭主程序窗口了,在任务栏里双击1st SMTP Server图标,可以看到它的主界面!这时,应该smtp服务就正常运行了,像dns和smtp端口之类的默认就好了。
第二步。设置php.ini
找到
[mail function]
SMTP = localhost
smtp_port = 25
sendmail_from = web@phpd.cn
如果加了;的话,去掉就可以了,apache重启一下,这样php的mail()就可以正常工作了
1st SMTP Server 下载