php利用cookies 实现购物车

 更新时间:2016年11月25日 16:27  点击:2096
php 购物车是在电子商务网站会用到的,一种像超市购物车一样的,选好商品了,先放到自己的购物车里面等好了再到柜台结算,本款php购物车完全按照这个原理来实例的,下面我们来看看吧,利用了cookie来实现。
 代码如下 复制代码

<?php
/**
 * 购物车类 cookies 保存,保存周期为1天 注意:浏览器必须支持cookie才能够使用
 * 技术交流群:100352308
 */
class cartapi {
 private $cartarray = array(); // 存放购物车的二维数组
 private $cartcount; // 统计购物车数量
 public $expires = 86400; // cookies过期时间,如果为0则不保存到本地 单位为秒
 /**
  * 构造函数 初始化操作 如果$id不为空,则直接添加到购物车
  *
  */
 public function __construct($id = "",$name = "",$price1 = "",$price2 = "",$price3 = "",$count = "",$image = "",$expires = 86400) {
  if ($id != "" && is_numeric($id)) {
   $this->expires = $expires;
   $this->addcart($id,$name,$price1,$price2,$price3,$count,$image);
  }
 }
 /**
  * 添加商品到购物车
  *
  * @param int $id 商品的编号
  * @param string $name 商品名称
  * @param decimal $price1 商品价格
  * @param decimal $price2 商品价格
  * @param decimal $price3 商品价格
  * @param int $count 商品数量
  * @param string $image 商品图片
  * @return 如果商品存在,则在原来的数量上加1,并返回false
  */
 public function addcart($id,$name,$price1,$price2,$price3,$count,$image) {
  $this->cartarray = $this->cartview(); // 把数据读取并写入数组
  if ($this->checkitem($id)) { // 检测商品是否存在
   $this->modifycart($id,$count,0); // 商品数量加$count
   return false;
  }
  $this->cartarray[0][$id] = $id;
  $this->cartarray[1][$id] = $name;
  $this->cartarray[2][$id] = $price1;
  $this->cartarray[3][$id] = $price2;
  $this->cartarray[4][$id] = $price3;
  $this->cartarray[5][$id] = $count;
  $this->cartarray[6][$id] = $image;
  $this->save();
 }
 /**
  * 修改购物车里的商品
  *
  * @param int $id 商品编号
  * @param int $count 商品数量
  * @param int $flag 修改类型 0:加 1:减 2:修改 3:清空
  * @return 如果修改失败,则返回false
  */
 public function modifycart($id, $count, $flag = "") {
  $tmpid = $id;
  $this->cartarray = $this->cartview(); // 把数据读取并写入数组
  $tmparray = &$this->cartarray;  // 引用
  if (!is_array($tmparray[0])) return false;
  if ($id < 1) {
   return false;
  }
  foreach ($tmparray[0] as $item) {
   if ($item === $tmpid) {
    switch ($flag) {
     case 0: // 添加数量 一般$count为1
      $tmparray[5][$id] += $count;
      break;
     case 1: // 减少数量
      $tmparray[5][$id] -= $count;
      break;
     case 2: // 修改数量
      if ($count == 0) {
       unset($tmparray[0][$id]);
       unset($tmparray[1][$id]);
       unset($tmparray[2][$id]);
       unset($tmparray[3][$id]);
       unset($tmparray[4][$id]);
       unset($tmparray[5][$id]);
       unset($tmparray[6][$id]);
       break;
      } else {
       $tmparray[5][$id] = $count;
       break;
      }
     case 3: // 清空商品
      unset($tmparray[0][$id]);
      unset($tmparray[1][$id]);
      unset($tmparray[2][$id]);
      unset($tmparray[3][$id]);
      unset($tmparray[4][$id]);
      unset($tmparray[5][$id]);
      unset($tmparray[6][$id]);
      break;
     default:
      break;
    }
   }
  }
  $this->save();
 }
 /**
  * 清空购物车
  *
  */
 public function removeall() {
  $this->cartarray = array();
  $this->save();
 }
 /**
  * 查看购物车信息
  *
  * @return array 返回一个二维数组
  */
 public function cartview() {
  $cookie = strips教程lashes($_cookie['cartapi']);
  if (!$cookie) return false;
  $tmpunserialize = unserialize($cookie);
  return $tmpunserialize;
 }
 /**
  * 检查购物车是否有商品
  *
  * @return bool 如果有商品,返回true,否则false
  */
 public function checkcart() {
  $tmparray = $this->cartview();
  if (count($tmparray[0]) < 1) {   
   return false;
  }
  return true;
 }
 /**
  * 商品统计
  *
  * @return array 返回一个一维数组 $arr[0]:产品1的总价格 $arr[1:产品2得总价格 $arr[2]:产品3的总价格 $arr[3]:产品的总数量
  */
 public function countprice() {
  $tmparray = $this->cartarray = $this->cartview();
  $outarray = array(); //一维数组
  // 0 是产品1的总价格
  // 1 是产品2的总价格
  // 2 是产品3的总价格
  // 3 是产品的总数量
  $i = 0;
  if (is_array($tmparray[0])) {
   foreach ($tmparray[0] as $key=>$val) {
    $outarray[0] += $tmparray[2][$key] * $tmparray[5][$key];
    $outarray[1] += $tmparray[3][$key] * $tmparray[5][$key];
    $outarray[2] += $tmparray[4][$key] * $tmparray[5][$key];
    $outarray[3] += $tmparray[5][$key];
    $i++;
   }
  }
  return $outarray;
 }
 /**
  * 统计商品数量
  *
  * @return int
  */
 public function cartcount() {
  $tmparray = $this->cartview();
  $tmpcount = count($tmparray[0]);
  $this->cartcount = $tmpcount;
  return $tmpcount;
 }
 /**
  * 保存商品 如果不使用构造方法,此方法必须使用
  *
  */
 public function save() {
  $tmparray = $this->cartarray;
  $tmpserialize = serialize($tmparray);
  setcookie("cartapi",$tmpserialize,time()+$this->expires);
 }
 /**
  * 检查购物车商品是否存在
  *
  * @param int $id
  * @return bool 如果存在 true 否则false
  */
 private function checkitem($id) {
  $tmparray = $this->cartarray;
  if (!is_array($tmparray[0])) return;
  foreach ($tmparray[0] as $item) {
   if ($item === $id) return true;
  }
  return false;
 }
}
?>

现在流行的网站支持平台,支付宝当仁不让的老大了,现在我们就来告诉你如何使用支付宝api来做第三方支付,把支付宝放到自己网站来哈。
 代码如下 复制代码

*/
//alipay_config.php 配置程序
$interfaceurl = "https://www.alipay.com/payto:";
$sitename  = "网站名称";
$weburl   = "http://网站网址";
$o_fee   = "0.00";              //平邮费
$e_fee   = "0.00";              //快递费
$selleremail  = "";//支付宝账号
$payalikey  = "";//安全校验码
$imgurl   = "pay.gif"; //按钮图片源
$imgtitle  = "使用支付宝购买";           //按钮图片说明
?>
<?php
/*********************************************************************
 filename: alipay.php
 author:  dboyzhang
 version:  ver 2.0.0 beta1
 contact_me: wangwang:dboyzhang
*********************************************************************/

//alipay.php代码
require_once("alipay_config.php");
class alipay
{
 function geturl($s1,$s2,$s3,$s4,$s5,$s6,$s7,$s8,$s9,$s10,$s11,$s12,$s13,$s14,$s15,$s16,$s17,$s18,$s19,$s20,$s21,$s22,$s23)
 {
  $parameter = array(
    'cmd'   => $s1,
    'subject'  => $s2,
    'body'   => $s3,
    'order_no'  => $s4,
    'price'   => $s5,
    'url'   => $s6,
    'type'   => $s7,
    'number'  => $s8,
    'transport'  => $s9,
    'ordinary_fee'  => $s10,
    'express_fee'  => $s11,
    'readonly'  => $s12,
    'buyer_msg'  => $s13,
    'seller'  => $s14,
    'buyer'   => $s15,
    'buyer_name'  => $s16,
    'buyer_address'  => $s17,
    'buyer_zipcode'  => $s18,
    'buyer_tel'  => $s19,
    'buyer_mobile'  => $s20,
    'partner'  => $s21,
  );

  $url = $s22.$s14."?";
  foreach($parameter as $key => $value){
    if($value){
      $url  .= $key."=".urlencode($value)."&";
      $acsouce .=$key.$value;
    }
  }
  $url  .= 'ac='.md5($acsouce.$s23);
  return $url;

 }
}
?>

pay.php页面

<?
error_reporting(0);
$aliname=$_post["aliname"];
$alizipcode=$_post["alizipcode"];
$aliphone=$_post["aliphone"];
$aliaddress=$_post["aliaddress"];
$aliorder=$_post["aliorder"];
$alimailtype=$_post["alimailtype"];
$alimoney=$_post["alimoney"];
$alimob=$_post["alimob"];
$alibody=$_post["alibody"];
?>
<?
require_once("alipay_config.php");
require_once("alipay.php");


$cmd   = '0001';
$subject  = "订单号:".$aliorder;
$body   = '商品介绍';
$order_no  = $aliorder;
$price   = $alimoney;
$url   = 'www.111cn.net';//你的网址
$type   = '1';
$number   =  '1';
$transport  = $alimailtype;
$ordinary_fee  = '0.00';
$express_fee  = '0.00';
$readonly  = 'true';
$buyer_msg  = $alibody;
$seller   = $selleremail;
$buyer   = '';
$buyer_name  = $aliname;
$buyer_address  = $aliaddress;
$buyer_zipcode  = $alizipcode;
$buyer_tel  = $aliphone;
$buyer_mobile  = $alimob;
$partner  = '2088002008096997';

$geturl = new alipay;
$link = $geturl->geturl
 (
 $cmd,$subject,$body,$order_no,$price,$url,$type,$number,$transport,
 $ordinary_fee,$express_fee,$readonly,$buyer_msg,$seller,$buyer,
 $buyer_name,$buyer_address,$buyer_zipcode,$buyer_tel,$buyer_mobile,$partner,
 $interfaceurl,$payalikey
 );
?>
<html>
<head>
<title>简易支付宝付款php版</title>
<link href="admin_style.css教程" rel=stylesheet>
<meta http-equiv=content-type content="text/html; charset=gb2312">
</head>

<body>
<table class=border id=table1 style="font-size: 9pt" height=185 cellspacing=0
cellpadding=0 width=492 align=center border=0>
  <tbody>
  <tr>
    <td class=topbg height=30>
      <div align=center><strong>简易支付宝付款php版</strong></div></td></tr>
  <tr>
    <td style="border-left: #e4e4e4 1px solid; border-bottom: #e4e4e4 1px solid" colspan=3 height=150>
      <table style="font-size: 9pt" height=137 width="100%" align=center bgcolor=#ffffff>
        <tbody>
        <tr class=tdbg>
          <td width="14%">订单号码:</td>
          <td width="86%"><? echo $aliorder; ?></td></tr>
        <tr class=tdbg>
          <td width="14%">收 货 人:</td>
          <td width="86%"><? echo $aliname; ?></td></tr>
        <tr class=tdbg>
          <td width="14%">付款金额:</td>
          <td width="86%"><b><? echo $alimoney; ?></b></td></tr>
        <tr class=tdbg>
          <td width="14%">收货地址:</td>
          <td width="86%"><? echo $aliaddress; ?></td></tr>
        <tr class=tdbg>
          <td>物流方式:</td>
          <td><? echo $alimailtype; ?> (1.平邮 2.快递 3.虚拟物品)</td></tr>
        <tr class=tdbg>
          <td>联系电话:</td>
          <td><? echo $aliphone; ?></td></tr>
        <tr class=tdbg>
          <td>邮政编码:</td>
          <td><? echo $alizipcode; ?></td></tr>
        <tr class=tdbg>
          <td>手机号码:</td>
          <td><? echo $alimob; ?></td></tr>
        <tr class=tdbg>
          <td>客户留言:</td>
          <td><? echo $alibody; ?></td></tr>
        <tr class=tdbg>
          <td></td>
          <td><input type="button" name="submit21" onclick="网页特效:history.go(-1)" value="返回修改订单">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="<?php echo $link?>" target="_blank"><img src="<?php echo $imgurl?>" alt="<?php echo $imgtitle?>" border="0" align='absmiddle' border='0'/></a> </td></tr></tbody></table></td></tr></tbody></table>
 
</body></html>

 

提供一款超完美的php文件在线压缩程序,原理很简单就是把文件以二进制形式保存了,以前用过利用rar的内核程序,这是php自带的压缩功能。
 代码如下 复制代码

set_time_limit(0);
class phpzip{

    var $file_count = 0 ;
    var $datastr_len   = 0;
    var $dirstr_len = 0;
    var $filedata = ''; //该变量只被类外部程序访问
    var $gzfilename;
    var $fp;
    var $dirstr='';

    /*
    返回文件的修改时间格式.
    只为本类内部函数调用.
    */
    function unix2dostime($unixtime = 0) {
        $timearray = ($unixtime == 0) ? getdate() : getdate($unixtime);

        if ($timearray['year'] < 1980) {
        $timearray['year']    = 1980;
        $timearray['mon']     = 1;
        $timearray['mday']    = 1;
        $timearray['hours']   = 0;
        $timearray['minutes'] = 0;
        $timearray['seconds'] = 0;
        }

        return (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) | ($timearray['mday'] << 16) |
               ($timearray['hours'] << 11) | ($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1);
    }
    /*
    初始化文件,建立文件目录,
    并返回文件的写入权限.
    */
    function startfile($path = 'faisun.zip'){
       $this->gzfilename=$path;
       $mypathdir=array();
       do{
        $mypathdir[] = $path = dirname($path);
       }while($path != '.');
       @end($mypathdir);
       do{
        $path = @current($mypathdir);
        @mkdir($path);
       }while(@prev($mypathdir));

       if($this->fp=@fopen($this->gzfilename,"w")){
        return true;
       }
       return false;
    }
    /*
    添加一个文件到 zip 压缩包中.
    */
   

 

<?php教程
/**
 * gd image mask
 *
 * @copyright ugia.cn

 */
function imagemask(&$im, $x1, $y1, $x2, $y2, $deep)
{
    for($x = $x1; $x < $x2; $x += $deep)
    {
        for ($y = $y1; $y < $y2; $y += $deep)
        {
            $color = imagecolorat ($im, $x + round($deep / 2), $y + round($deep / 2));
            imagefilledrectangle ($im, $x, $y, $x + $deep, $y + $deep, $color);
        }
    }
}
?>


  示例:
<?php
header("content-type: image/png");
$im = imagecreatefromjpeg("test.jpg");
imagemask($im, 57, 22, 103, 40, 8);
imagepng($im);
imagedestroy($im);
?>

 


<?php
/**
 * gd image text outer
 *
 * @copyright ugia.cn

 */
function imagetextouter(&$im, $size, $x, $y, $color, $fontfile, $text, $outer)
{
    if (!function_exists('imagecolorallocatehex'))
    {
        function imagecolorallocatehex($im, $s)
        {
           if($s{0} == "#") $s = substr($s,1);
           $bg_dec = hexdec($s);
           return imagecolorallocate($im,
                       ($bg_dec & 0xff0000) >> 16,
                       ($bg_dec & 0x00ff00) >>  8,
                       ($bg_dec & 0x0000ff)
                       );
        }
    }
    $ttf = false;
    if (is_file($fontfile))
    {
        $ttf = true;
        $area = imagettfbbox($size, $angle, $fontfile, $text);
        $width  = $area[2] - $area[0] + 2;
        $height = $area[1] - $area[5] + 2;
    }
    else
    {
        $width  = strlen($text) * 10;
        $height = 16;
    }
    $im_tmp = imagecreate($width, $height);
    $white = imagecolorallocate($im_tmp, 255, 255, 255);
    $black = imagecolorallocate($im_tmp, 0, 0, 0);
    $color = imagecolorallocatehex($im, $color);
    $outer = imagecolorallocatehex($im, $outer);
    if ($ttf)
    {
        imagettftext($im_tmp, $size, 0, 0, $height - 2, $black, $fontfile, $text);
        imagettftext($im, $size, 0, $x, $y, $color, $fontfile, $text);
        $y = $y - $height + 2;
    }
    else
    {
        imagestring($im_tmp, $size, 0, 0, $text, $black);
        imagestring($im, $size, $x, $y, $text, $color);
    }
    for ($i = 0; $i < $width; $i ++)
    {
        for ($j = 0; $j < $height; $j ++)
        {
            $c = imagecolorat($im_tmp, $i, $j);
            if ($c !== $white)
            {
                imagecolorat ($im_tmp, $i, $j - 1) != $white || imagesetpixel($im, $x + $i, $y + $j - 1, $outer);
                imagecolorat ($im_tmp, $i, $j + 1) != $white || imagesetpixel($im, $x + $i, $y + $j + 1, $outer);
                imagecolorat ($im_tmp, $i - 1, $j) != $white || imagesetpixel($im, $x + $i - 1, $y + $j, $outer);
                imagecolorat ($im_tmp, $i + 1, $j) != $white || imagesetpixel($im, $x + $i + 1, $y + $j, $outer);
                // 取消注释,与fireworks的发光效果相同
                /*
                imagecolorat ($im_tmp, $i - 1, $j - 1) != $white || imagesetpixel($im, $x + $i - 1, $y + $j - 1, $outer);
                imagecolorat ($im_tmp, $i + 1, $j - 1) != $white || imagesetpixel($im, $x + $i + 1, $y + $j - 1, $outer);
                imagecolorat ($im_tmp, $i - 1, $j + 1) != $white || imagesetpixel($im, $x + $i - 1, $y + $j + 1, $outer);
                imagecolorat ($im_tmp, $i + 1, $j + 1) != $white || imagesetpixel($im, $x + $i + 1, $y + $j + 1, $outer);
                */
            }
        }
    }
    imagedestroy($im_tmp);
}
?>


  示例:
<?php
header("content-type: image/png");
$im = imagecreatefromjpeg("bluesky.jpg");
$white = imagecolorallocate($im, 255,255,255);
imagetextouter($im, 9, 10, 20, '#000000', "simsun.ttc", '新年快乐', '#ffffff');
imagetextouter($im, 2, 10, 30, '#ffff00', "", 'hello, world!' , '#103993');
imagepng($im);
imagedestroy($im);
?>


  马赛克:void imagemask ( resource image, int x1, int y1, int x2, int y2, int deep)

  imagemask() 把坐标 x1,y1 到 x2,y2(图像左上角为 0, 0)的矩形区域加上马赛克。

  deep为模糊程度,数字越大越模糊。
描边:void imagetextouter ( resource image, int size, int x, int y, string color, string fontfile, string text, string outercolor)

  imagetextouter() 将字符串 text 画到 image 所代表的图像上,从坐标 x,y(左上角为 0, 0)开始,颜色为 color,边框所使用的颜色为 outercolor,使用 fontfile 所指定的 truetype 字体文件。

  如果不指定字体文件,则使用gd的内部字体。根据 php 所使用的 gd 库的不同,如果 fontfile 没有以 ‘/’开头,则 ‘.ttf’ 将被加到文件名之后并且会搜索库定义字体路径。

  如果指定了字体文件,由 x,y 所表示的坐标定义了第一个字符的基本点(大概是字符的左下角)。否则 x,y 定义了第一个字符的右上角。

  fontfile 是想要使用的 truetype 字体的文件名。

  text 是文本字符串,可以包含 utf-8 字符序列(形式为:{)来访问字体中超过前 255 个的字符。

  color 是十六进制的#rrggbb格式的颜色,如#ff0000为红色。

  outercolor 描边颜色,十六进制的#rrggbb格式。

这款国外的php图片上传代码是一款好的文件与图片上传代码,并且还支持文件在线管理哦,是一款比较的好图片管理系统哦。
 代码如下 复制代码

 define('max', 2);
 
 mysql教程_connect('localhost', 'your mysql username', 'your mysql password');
 mysql_select_db('your mysql database');
 
 switch ($_post['action']) {
  case 'upload':
  
   $file = $_files['file']['tmp_name'];
   $filename = $_files['file']['name'];
   
   if($file) {
   
    $max = max * 1024 * 1024;
    $q = mysql_query("select * from `uploads` order by `batch` desc limit 1");
    $r = mysql_fetch_assoc($q);
    $batch = $r['batch'];
    
    if($filename == 'upload.zip') {
    
     $zip = zip_open($file);

     if ($zip) {
     
      while ($zip_entry = zip_read($zip)) {
       
       $size = zip_entry_filesize($zip_entry);
       
       $name = zip_entry_name($zip_entry);
       
       $type = substr(strrchr($name, '.'), 1);
       
       if (zip_entry_open($zip, $zip_entry, "r")) {
       
        $content = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
        zip_entry_close($zip_entry);
         
       }
    
       if ($size > $max) {
       
        header('location: ./?error=4');
        exit;
        
       }
       
       $error = true;
       
       if ($type == 'gif' && $error) {
       
        $error = false;
        
       }
       
       if ($type == 'png' && $error) {
       
        $error = false;
        
       }
       
       if ($type == 'jpg' && $error) {
       
        $error = false;
        
       }
       
       if ($type == 'jpeg' && $error) {
       
        $error = false;
        
       }
       
       if ($error) {
       
        header('location: ./?error=2');
        
       } else {
       
        $id = 1;
        $batch2 = $batch + 1;
        
        while (file_exists("uploads/$id/$name")) {
        
         $id++;
         
        }
        @mkdir("uploads/$id");
        
        $fp = @fopen("uploads/$id/$name", "w");
        
        if (@fwrite($fp, $content)) {
        
         $q = mysql_query("insert into `uploads` (`file`, `batch`) values ('uploads/$id/$name', '$batch2')");
         $id = mysql_insert_id();
         
        } else {
        
         header('location: ./?error=3');
         
        }
        
        fclose($fp);
        
       }
     
      }
      
      header('location: ./?batch=' . $batch2);
      
      zip_close($zip);
     
     }
    
    } else {
    
     if (filesize($file) > $max) {
     
      header('location: ./?error=4');
      exit;
      
     }
     
     $error = true;
     
     if (@imagecreatefromjpeg($file) && $error) {
     
      $error = false;
      
     }
     
     if (@imagecreatefromgif($file) && $error) {
     
      $error = false;
     }
     
     if (@imagecreatefrompng($file) && $error) {
     
      $error = false;
      
     }
     
     if ($error) {
     
      header('location: ./?error=2');
      
     } else {
     
      $id = 1;
      $batch = $batch + 1;
      
      while (file_exists("uploads/$id/$filename")) {
      
       $id++;
       
      }
      @mkdir("uploads/$id");
      
      if (@move_uploaded_file($file, "uploads/$id/$filename")) {
      
       $q = mysql_query("insert into `uploads` (`file`, `batch`) values ('uploads/$id/$filename', '$batch')");
       $id = mysql_insert_id();
       header('location: ./?image=' . $id);
       
      } else {
      
       header('location: ./?error=3');
       
      }
      
     }
    
    }
    
   } else {
   
    header('location: ./?error=1');
   
   }
   
   exit;
   
  break;
 }
 
 header('content-type: text/html; charset=iso-8859-1');
 ob_start('rewrite');
 function rewrite ($buffer) {
  $host = $_server['http_host'];
  $path = dirname($_server['php_self']);
  $absolute = "http://$host$path/";
  return preg_replace('#(href|src|action)="/#', "\1="$absolute", $buffer);
 }
 
?>
<!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>
  <title>jpegr - share photos instantly</title>
  <meta name="description" content="upload and share photos and images instantly, on jpegr.com" />
  <meta name="keywords" content="upload, upload images, share photos, photo sharing, image uploader" />
  <link href="/css教程/main.css" rel="stylesheet" />
  <script src="/mint/?js" type="text/网页特效"></script>
  <script src="/js/nb-object.js" type="text/javascript"></script>
 </head>
 <body>
  <h1><a href="http://jpeg.sn8.us/" title="goto jpegr home"><img src="/img/logo.gif" alt="jpegr" /></a></h1>
  <div id="menu">
   <form method="post" action="/" enctype="multipart/form-data" class="right">
    <input type="hidden" name="action" value="upload" />
    <label for="quick">quick upload</label>
    <input type="file" name="file" size="10" id="quick" />
    <input type="submit" value="upload" class="button" />
   </form>
   <a href="/">upload</a>
   <a href="/help/">help</a>
   <a href="/terms-of-service/">terms of service</a>
  </div>
  
<?php

 // recently uploaded query
 //$q = mysql_query('select * from `uploads` order by `id` desc limit 15');

 $q = mysql_query('select count(`id`) as `count` from `uploads`');
 $r = mysql_fetch_assoc($q);
 
?>
  <div id="main">
   <h2 class="right"><?php echo number_format($r['count']); ?> <strong>images hosted</strong></h2>
   
<?php

 if ($_get['p'] == 'help') {
 
?>
   <h2>help</h2>
   <div>
    <ul>
     <li>
      <strong>how do i upload an image?</strong><br />
      just use the quick upload form on the top, or goto the <a href="/">home page</a> to <a href="/">upload an image</a>.
     </li>
     <li>
      <strong>what does "you must select a file to upload!" mean?</strong><br />
      this means that you clicked <strong>upload</strong> without selecting an image file.
     </li>
     <li>
      <strong>what does "that is a not a valid jpeg, gif, or png image." mean?</strong><br />
      this means that you uploaded a file, but it was not a jpeg, gif, or png image.
     </li>
     <li>
      <strong>what does "there was a problem with the server, and we were unable to upload your image." mean?</strong><br />
      this means your file was accepted, but it did not get saved, you will need to <a href="/">try again</a>, or <a href="/">upload another image</a>.
     </li>
     <li>
      <strong>what does "the file you selected was too big, <em><?php echo max; ?>mb</em> is the maximum." mean?</strong><br />
      this means that you tried to upload a file that was too big.
     </li>
    </ul>
   </div>
<?php

 } elseif ($_get['p'] == 'terms-of-service') {
 
?>
   <h2>terms of service</h2>
   <div>
    <strong>when you upload to jpegr you agree to the following</strong>;
    <ul>
     <li>you will not use jpegr to upload pornographic content, any violation of this agreement may result in ban, and immediate removal of content.</li>
     <li>you will not abuse jpegr's upload form.</li>
     <li>any violation may result in permanent ban.</li>
    </ul>
   </div>
<?php

 } else {
 
  if (is_numeric($_get['image'])) {
  
   $q = mysql_query("select * from `uploads` where `id` = '$_get[image]'");
   $r = mysql_fetch_assoc($q);
   $root_ = 'http://' . $_server['http_host'] . dirname($_server['php_self']) . '/';
   
?>
   <h2>here is your image</h2>
   <div>
    <a href="/<?php echo $r['file']; ?>">click here to view your image</a><br /><br />
    <label for="direct">direct link to your image</label><br />
    <input type="text" id="direct" value="<?php echo $root_ . $r['file']; ?>" onfocus="this.select();" /><br />
    <label for="share" style="font-weight: bold;">share with your friends</label><br />
    <input type="text" id="share" value="<?php echo htmlspecialchars("$root_?image=$r[id]"); ?>" onfocus="this.select();" /><br />
    <label for="html">post link to myspace or website</label><br />
    <input type="text" id="html" value="<?php echo htmlspecialchars("<a href="$root_"><img src="$root_$r[file]" alt="visit jpegr" /></a>"); ?>" onfocus="this.select();" /><br />
    <label for="forum">post to a forum</label><br />
    <input type="text" id="forum" value="<?php echo htmlspecialchars("[url=$root_][img]$root_$r[file][/img][/url]"); ?>" onfocus="this.select();" /><br />
    if you want to <a href="/">upload another image</a>, you can go back or use the form below!<br /><br />
   </div>
<?php

  }
  
  if (is_numeric($_get['batch'])) {
  
   $q = mysql_query("select * from `uploads` where `batch` = '$_get[batch]'");
   
?>
   <h2>viewing batch #<?php echo ($_get['batch']) ? $_get['batch'] : 0; ?></h2>
   <div>
    to view an image in full size, just click it.<br /><br />
   
<?php

   while($r = mysql_fetch_assoc($q)) {

?>
    <a href="<?php echo $r['file']; ?>"><img src="<?php echo $r['file']; ?>" alt="image #<?php echo $r['id']; ?>" border="0" style="max-width: 75px;" /></a>
<?php

   }
   
?>
   <br /><br />
   
   <div id="slider">
    <h3>beta image slideshow</h3>
    <noscript>please turn on javascript to view our slideshows.</noscript>
    <div id="slide"></div>
   </div>
   
   <script type="text/javascript">
    
    <?php
     
     $qq = mysql_query("select * from `uploads` where `batch` = '$_get[batch]'");
     
     while($rr = mysql_fetch_assoc($qq)) {
 
    ?>
nb.slideshow.addimage('<?php echo $rr['file']; ?>');
    <?php
    
     }
       
    ?>
nb.slideshow.start();
    
   </script>
   
   </div>
   
   <h2>share this batch with your friends</h2>
   <div>
   
    <label for="share" style="font-weight: bold;">batch viewer</label><br />
    <input type="text" id="share" value="http://jpeg.sn8.us/?batch=<?php echo ($_get['batch']) ? $_get['batch'] : 0; ?>" onfocus="this.select();" /><br />
    if you want to <a href="/">upload another batch</a>, you can go back or use the form below!<br /><br />
   </div>
<?php

  }
 
?>
   <h2>upload an image or photo</h2>
   <form method="post" action="/" enctype="multipart/form-data">
    <input type="hidden" name="action" value="upload" />
<?php

  switch ($_get['error']) {
   case 1:
    $error = 'you must select a file to upload!<br />';
   break;
   case 2:
    $error = 'that is a not a valid jpeg, gif, or png image.<br />';
   break;
   case 3:
    $error = 'there was a problem with the server, and we were unable to upload your image.<br />';
   break;
   case 4:
    $error = 'the file you selected was too big, <strong>' . max . 'mb</strong> is the maximum.<br />';
   break;
  }
  
?>
    <font color="#ff0004"><?php echo $error; ?></font>
    you can upload a <strong>jpeg</strong>, <strong>gif</strong>, or <strong>png</strong> image. (max <strong><?php echo max; ?>mb</strong>)<br /><br />
    
    you can also upload a <strong>zip</strong> named <strong>upload.zip</strong>, containing multiple images.<br /><br />
    
    <label for="file">choose your file</label><br />
    <input type="file" name="file" size="40" id="file" /><br />
    <input type="submit" value="upload" class="button" />
   </form>
<?php

 }
 
?>
  </div>
  
  </div>
 </body>
</html>

??????
<?php
 mysql_connect('localhost', 'your mysql username', 'your mysql password');
 mysql_select_db('your mysql database');
 if ($_get['delete']) {
  $sql = "select * from `uploads` where `id` = '$_get[delete]'";
  $q = mysql_query($sql);
  $r = mysql_fetch_assoc($q);
  unlink($_server['document_root'] . '/' . $r['file']);
  $sql = "delete from `uploads` where `id` = '$_get[delete]'";
  $q = mysql_query($sql);
  header('location: ' . $_server['http_referer']);
  exit;
 }
?>
<!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>jpegr administration</title>
  <style type="text/css">
   body {
    font-family: sans-serif;
    font-size: 12px;
    width: 800px;
    margin: 40px auto;
   }
   a {
    color: #105cb6;
    text-decoration: none;
   }
   a:hover {
    text-decoration: underline;
   }
   td {
    padding: 4px;
   }
   .head {
    font-weight: bold;
    color: #ffffff;
    background-color: #222222;
   }
   .item {
    background-color: #f2f2f2;
   }
   .one {
    width: 60px;
    text-align: center;
   }
   .three {
    width: 80px;
    text-align: center;
   }
   .page, .current {
    display: block;
    float: left;
    padding: 2px 4px;
    margin: 0px 4px 8px 0px;
   }
   .page {
    color: #000000;
    background-color: #eeeeee;
   }
   .current {
    font-weight: bold;
    color: #ffffff;
    background-color: #222222;
   }
  </style>
 </head>
 <body>
<?php
 $sql = 'select ceil(count(`id`) / 20) as `count` from `uploads`';
 $q = mysql_query($sql);
 $r = mysql_fetch_assoc($q);
 $pages = $r['count'];
 $offset = ($_get['page'] > 0 && $_get['page'] <= $pages) ? ($_get['page'] - 1) * 20 : 0;
 for ($i = 1; $i <= $pages; $i++) {
  $class = ($_get['page'] == $i || $i == 1 && !$_get['page']) ? ' class="current"' : ' class="page"';
?>
  <a href="?page=<?php echo $i; ?>"<?php echo $class; ?>><?php echo $i; ?></a>
<?php
 }
?>
  <br clear="all" />
  <table width="100%">
   <tr class="head">
    <td class="one">id</td>
    <td class="two">filename</td>
    <td class="three">action</td>
   </tr>
<?php
 $sql = "select * from `uploads` order by `id` desc limit $offset,20";
 $q = mysql_query($sql);
 while ($r = mysql_fetch_assoc($q)) {
?>
   <tr class="item">
    <td class="one"><?php echo number_format($r['id']); ?></td>
    <td class="two"><?php echo $r['file']; ?></td>
    <td class="three"><a href="/<?php echo $r['file']; ?>" target="_blank">view</a>, <a href="?delete=<?php echo $r['id']; ?>" onclick="return confirm('are you sure you want to delete &quot;<?php echo $r['file']; ?>&quot;?');">delete</a></td>
   </tr>
<?php
 }
?>
  </table>
 </body>
</html>

css??
html, body {
 font-family: sans-serif;
 font-size: 12px;
 width: 800px;
 margin: 40px auto;
}
a {
 color: #105cb6;
 text-decoration: none;
}
h1 {
 margin: 0px 0px 10px 0px;
}
h1 a {
 -moz-outline-width: 0px;
}
h1 a img {
 border: 0px;
}
h3 {
 margin: 4px;
}
a:hover {
 text-decoration: underline;
}
#menu {
 background-color: #e5f5ff;
 padding: 8px;
 border: 1px solid #0099ff;
 position: relative;
}
#menu a {
 font-weight: bold;
 margin: 0px 8px 0px 0px;
}
#menu a:hover {
 text-decoration: underline;
}
#menu .right {
 margin: 0px;
 padding: 0px;
 position: absolute;
 top: 4px;
 right: 4px;
}
#menu .input {
 background-color: #ffffff;
 padding: 2px;
 border: 1px solid #0066ff;
}
#menu .button {
 font-family: sans-serif;
 padding: 2px;
 cursor: pointer;
}
#menu label {
 cursor: pointer;
}
#ads {
 background-color: #fde5f3;
 margin: 8px 0px;
 border: 1px solid #ec008c;
}
#recent {
 background-color: #e6fec9;
 margin: 8px 0px;
 padding: 2px;
 border: 1px solid #9dca68;
}
#main {
 background-color: #fffee5;
 padding: 8px;
 border: 1px solid #fff200;
}
#main h2 {
 font-size: 16px;
 color: #222222;
 margin: 0px;
}
#main form {
 margin: 4px 8px;
}
#main label {
 cursor: pointer;
}
#main .button {
 font-family: sans-serif;
 margin: 2px 0px 0px 0px;
 padding: 2px;
 cursor: pointer;
}
#main .right {
 font-size: 14px;
 float: right;
 padding: 0px 0px 2px 0px;
 border-bottom: 1px solid #444444;
}
#main div {
 margin: 4px 8px;
}
#main div label {
 font-weight: bold;
}
#main div input {
 font-family: sans-serif;
 font-size: 12px;
 width: 680px;
 padding: 2px;
 margin: 2px 0px 4px 4px;
}
#main div li {
 margin-bottom: 8px;
}
#links {
 background-color: #e9e8e8;
 margin: 8px 0px 0px 0px;
 padding: 4px 0px;
 border: 1px solid #231f20;
}
.spacer {
 height: 4px;
 overflow: hidden;
}

#slider {
 color: #ffffff;
 background-color: #232323;
 height: 400px;
 margin: 10px;
 padding: 5px;
 border: 1px solid #121212;
}

#slider h3 {
 color: #ffffff;
 font-size: 14px;
 line-height: 20px;
 background-color: #343434;
 height: 20px;
 margin: -5px -5px 15px -5px;
 padding: 5px;
}

#slider #slide #image {
 max-height: 350px;
}

源码下载地址

http://down.111cn.net/php/2010/0927/20956.html

[!--infotagslink--]

相关文章

  • phpems SQL注入(cookies)分析研究

    PHPEMS(PHP Exam Management System)在线模拟考试系统基于PHP+Mysql开发,主要用于搭建模拟考试平台,支持多种题型和展现方式,是国内首款支持题冒题和自动评分与教师评分相...2016-11-25
  • ASP.NET购物车实现过程详解

    这篇文章主要为大家详细介绍了ASP.NET购物车的实现过程,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-09-22
  • php语言实现redis的客户端

    php语言实现redis的客户端与服务端有一些区别了因为前面介绍过服务端了这里我们来介绍客户端吧,希望文章对各位有帮助。 为了更好的了解redis协议,我们用php来实现...2016-11-25
  • jQuery+jRange实现滑动选取数值范围特效

    有时我们在页面上需要选择数值范围,如购物时选取价格区间,购买主机时自主选取CPU,内存大小配置等,使用直观的滑块条直接选取想要的数值大小即可,无需手动输入数值,操作简单又方便。HTML首先载入jQuery库文件以及jRange相关...2015-03-15
  • JS实现的简洁纵向滑动菜单(滑动门)效果

    本文实例讲述了JS实现的简洁纵向滑动菜单(滑动门)效果。分享给大家供大家参考,具体如下:这是一款纵向布局的CSS+JavaScript滑动门代码,相当简洁的手法来实现,如果对颜色不满意,你可以试着自己修改CSS代码,这个滑动门将每一...2015-10-21
  • JS使用cookie实现DIV提示框只显示一次的方法

    本文实例讲述了JS使用cookie实现DIV提示框只显示一次的方法。分享给大家供大家参考,具体如下:这里运用JavaScript的cookie技术,控制网页上的提示DIV只显示一次,也就是当用户是第一次打开网页的时候才显示,第二次自动隐藏起...2015-11-08
  • jQuery+slidereveal实现的面板滑动侧边展出效果

    我们借助一款jQuery插件:slidereveal.js,可以使用它控制面板左右侧滑出与隐藏等效果,项目地址:https://github.com/nnattawat/slideReveal。如何使用首先在页面中加载jquery库文件和slidereveal.js插件。复制代码 代码如...2015-03-15
  • PHP+jQuery翻板抽奖功能实现

    翻板抽奖的实现流程:前端页面提供6个方块,用数字1-6依次表示6个不同的方块,当抽奖者点击6个方块中的某一块时,方块翻转到背面,显示抽奖中奖信息。看似简单的一个操作过程,却包含着WEB技术的很多知识面,所以本文的读者应该熟...2015-10-21
  • SQLMAP结合Meterpreter实现注入渗透返回shell

    sqlmap 是一个自动SQL 射入工具。它是可胜任执行一个广泛的数据库管理系统后端指印, 检索遥远的DBMS 数据库等,下面我们来看一个学习例子。 自己搭建一个PHP+MYSQ...2016-11-25
  • PHP中SSO Cookie登录分析和实现

    什么是SSO?单点登录SSO(Single Sign-On)是身份管理中的一部分。SSO的一种较为通俗的定义是:SSO是指访问同一服务器不同应用中的受保护资源的同一用户,只需要登录一次,即通过一个应用中的安全验证后,再访问其他应用中的受保护...2015-11-08
  • PHP实现今天是星期几的几种写法

    复制代码 代码如下: // 第一种写法 $da = date("w"); if( $da == "1" ){ echo "今天是星期一"; }else if( $da == "2" ){ echo "今天是星期二"; }else if( $da == "3" ){ echo "今天是星期三"; }else if( $da == "4"...2013-10-04
  • JS实现购物车中商品总价计算

    这篇文章主要为大家详细介绍了JS实现购物车中商品总价的计算 ,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-03-07
  • PHP中SSO Cookie登录分析和实现

    什么是SSO?单点登录SSO(Single Sign-On)是身份管理中的一部分。SSO的一种较为通俗的定义是:SSO是指访问同一服务器不同应用中的受保护资源的同一用户,只需要登录一次,即通过一个应用中的安全验证后,再访问其他应用中的受保护...2015-11-08
  • vue项目中js-cookie的使用存储token操作

    这篇文章主要介绍了vue项目中js-cookie的使用存储token操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-11-14
  • 原生js实现fadein 和 fadeout淡入淡出效果

    js里面设置DOM节点透明度的函数属性:filter= "alpha(opacity=" + value+ ")"(兼容ie)和opacity=value/100(兼容FF和GG)。 先来看看设置透明度的兼容性代码: 复制代码 代码如下: function setOpacity(ele, opacity) { if (...2014-06-07
  • React列表栏及购物车组件使用详解

    这篇文章主要为大家详细介绍了React列表栏及购物车组件使用,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-06-28
  • 什么是cookie?js手动创建和存储cookie

    什么是cookie? cookie 是存储于访问者的计算机中的变量。每当同一台计算机通过浏览器请求某个页面时,就会发送这个 cookie。你可以使用 JavaScript 来创建和取回 cookie 的值。 有关cookie的例子: 名字 cookie 当访...2014-05-31
  • Android中用HttpClient实现Http请求通信

    本文我们需要解决的问题是如何实现Http请求来实现通信,解决Android 2.3 版本以后无法使用Http请求问题,下面请看正文。 Android开发中使用HttpClient来开发Http程序...2016-09-20
  • vue实现简单购物车案例

    这篇文章主要为大家详细介绍了vue实现简单购物车案例,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-06-01
  • python爬虫用request库处理cookie的实例讲解

    在本篇内容里小编给大家整理的是一篇关于python爬虫用request库处理cookie的实例讲解内容,有需要的朋友们可以学习参考下。...2021-02-21