您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php 常用的文件上传类-可多文件上传

2025/1/7 1:38:58发布21次查看
upfile = $upfile;
        $this->upfile_name = $upfile_name;
        $this->upfile_size = $upfile_size;
        $this->new_upfile_name = $this->createnewfilename($this->upfile_name);
        $this->f1 = public/upload/images;
        $this->f2 = $this->f1./.date('y').-.date('m');
        $this->f3 = $this->f2./.date('d');
        $this->filename = $this->f3 . / . $this->new_upfile_name;
        $this->maxsize = 5000*1024;    # 文件大小 5000kb
        $this->file_type = gif/jpg/jpeg/png/bmp; # 允许上传的文件类型
 }
 # 创建新文件名 (原文件名)
 function createnewfilename($file_name){
    $this->fleth = explode(.,$file_name);
    $this->fileextent = $this->fleth[(int)count($this->fleth)-1]; # 获取文件后缀;
    $tmps教程tr = date('ymd').rand(0,time()) . . .$this->fileextent;    # 创建新文件名;
    return $tmpstr;
 }
 # 检测文件类型是否正确
 function chk_fileextent(){
    $iwtrue = 0;
    $fle = explode(/,$this->file_type);
    for($i=0; $i      if($this->fileextent == $fle[$i]){
     $iwtrue = (int) $iwtrue + 1;
     }
    }
    if( $iwtrue == 0 ){
  $this->msg(文件不符合 .$this->file_type. 格式!);
    }
 }
 # 提示错误信息并终止操作
 function msg($error){
    echo ;
    die();
 }
 # 保存文件
 function savefile(){
    $this->chk_fileextent();
    $this->chk_filesize();
    $this->createfolder( ./.$this->f1 );
    $this->createfolder( ./.$this->f2 );
    $this->createfolder( ./.$this->f3 );
    return $this->chk_savefile();
 }
 # 检测上传结果是否成功
 function chk_savefile(){
    $copymsg = copy($this->upfile,./.$this->filename);
    if( $copymsg ){
   return $this->filename;
    }
    else{
   $this->msg(文件上传失败! 请重新上传! );
    }
 }
 # 创建文件夹
 function createfolder($foldername){
    if( !is_dir($foldername) ){
   mkdir($foldername,0777);
    }
 }
 # 检测文件大小
 function chk_filesize(){
    if( $this->upfile_size > $this->maxsize ){
  $this->msg(目标文件不能大于. $this->maxsize/1024 . kb);
    }
 }
 # 删除文件($filepath 文件相对路径)
 function deletefile($filepath){
    if( !is_file($filepath) ){
   return false;
    }
    else{
   $ending = @unlink($filepath);
   return $ending;
    }
 }
}
?>
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product