[CODE:]文件上传类
require_once(SET_DB);
class UpFile{
private $pic; //图片地址数组
private $type; //记录用户设置的上传类型
public function upfiles($pic,$date){ //函数开始 传入表单名和时间
$uploadfile = dirname(__FILE__)."/..".Pic::$PIC_SRC.$date.$_FILES[$pic]["name"];
if(move_uploaded_file($_FILES[$pic]["tmp_name"],$uploadfile)){ //开始上传
$this -> pic[$pic] = Pic::$PIC_SRC.$date.$_FILES[$pic]["name"]; //成功则记录图片地址
return true; //并返回TRUE
}else{
return false; //失败返回false
}
}
public function getpic($pic){ //获取该表单的图片地址
return $this -> pic[$pic];
}
public function settype($type){ //设置上传文件类型
$this -> type = $type;
}
public function Compared_file($pic){ //比较上传文件的类型是否相符
if(Pic::$Big_Small){ //设置是否区分大小写
$coms = strstr($this -> type,substr(strrchr($_FILES[$pic]["name"], "."), 1)); //截取上传文件的后缀名并对比--区分大小写
}else{
$coms = strstr(strtoupper($this -> type),strtoupper(substr(strrchr($_FILES[$pic]["name"], "."), 1))); //截取上传文件的后缀名并对比--不区分大小写
}
if($coms){ //非空则返回TRUE,否则返回FALSE
return true;
}else{
return false;
}
}
}
?>
[CODE:]相关设置
?
final class Base{
public static $DB_DSN = "mysql:host=localhost;dbname=888888";
public static $DB_USER = "*****";
public static $DB_PW = "*******";
public static $DB_DRIVER_OPTIONS = array(
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'",
PDO::ATTR_PERSISTENT => false
);
public static $SID = "61661";
#------------------------评论系统----------------------------#
#------------------------菜单系统----------------------------#
public static $Menu_Left = "menu_cls"; //无限级菜单
}
final class Pic{
public static $PIC_SRC = "./UpFiles/"; //设置文件上传路径
public static $Big_Small = false; //区分大小写 TRUE区分 FLASE不区分
}
?>
[CODE:]使用
$pic = new UpFile();
if($_POST["Action"]=="ADD"){
$pic -> settype("jpg|gif|bmp|png"); //设置上传文件类型
if($pic -> Compared_file("pic_s")==true && $pic -> Compared_file("pic_b")==true){ //核对上传文件类型
if($pic -> upfiles("pic_s",date("Y-m-d-H-i-s")."S")){ $infs = true; }else{ $infs = false; } //第一个:上传并检查错误
if($pic -> upfiles("pic_b",date("Y-m-d-H-i-s")."B")){ $infs1 = true; }else{ $infs1 = false; } //第二个:上传并检查错误
#echo dirname(__FILE__)."/..".Pic::$PIC_SRC;
if($infs == true && $infs1 == true){ //如果上传正确
$link -> Inf_right("操作成功","new_image.php");
}else{
$link -> Inf_wrong("上传文件失败");
}
}else{ 类型错误,提示错误
$link -> Inf_wrong("上传文件类型错误");
}
}
?>