仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1466|回复: 19
打印 上一主题 下一主题

[学习教程] PHP网页设计跟我学做PHP上传类

[复制链接]
兰色精灵 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-2-3 23:30:05 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
终于学会把表单的数据插入数据库,然后显示出来了,应该说一个程序的雏形已经诞生了。   

  up.class.php
   
<?php    class up{     public $f; //暗示$_FILES[xx]     public $s; //上传文件的巨细 public $n; //是不是指定文件名 public $d; //是不是指定文件夹   function __construct($f,$s=1,$n=false,$d=false){  $this->f=$f;  $this->s=$s*1000000;  $this->n=$n;  $this->d=$d;  $this->loading(); }      function loading(){     $this->fsize(); $this->ftype(); $this->fmv();   }      function fname(){     if($this->n){ return $this->n.$this->ftype(); }else{ return time().rand(111,999).$this->ftype(); }   }      function fdir(){  if($this->d){  //判别用户是不是指定文件夹名 if(!is_dir($this->d)){ //判别指定的文件夹名是不是存在 mkdir($this->d); } return $this->d."/";  }else{  if(!is_dir(date("Ymd"))){ mkdir(date("Ymd")); } return date("Ymd")."/";  }   } //end fdir      function fsize(){     if($this->f['size']>$this->s){ echo "文件超越巨细"; exit(); }else{  return true; }   }      function ftype(){  switch($this->f['type']){ case "image/x-png": $ok=".png"; break; case "image/png": $ok=".png"; break; case "application/pdf": $ok=".pdf"; break; case "image/pjpeg": $ok=".jpg"; break; case "image/jpeg": $ok=".jpg"; break; case "image/jpg": $ok=".jpg"; break; default: $ok=false; break; } if($ok){   return $ok; }else{  echo "文件类型不准确";  exit(); }   }       function fmv(){      move_uploaded_file($this->f['tmp_name'],$this->fdir().$this->fname());    }      }     ?>   test.php 上传文件   <?php include("up.class.php");  if(!empty($_POST['sub'])){   foreach($_FILES as $id=>$v){   new up($_FILES[$id]);   }  }  ?> <form action="" method="post" enctype="multipart/form-data"> <input type="file" name="p1"><br> <input type="file" name="p2"><br> <input type="file" name="p3"><br> <input type="file" name="p4"><br> <input type="file" name="p5"><br> <input type="file" name="p6"><br> <input type="submit" name="sub" value="上传"> </form>     我先把我自己学习PHP的过程做一下概括:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-16 13:54

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表