search
Homephp教程PHP源码php 常用的文件上传类-可多文件上传

<script>ec(2);</script>

class My_Lib_upfile{

 var $upfile, $upfile_name, $upfile_size;
 # $upfile 临时文件名 $_FILES['tmp_name'] ,$upfile_name 文件名 $_FILES['name'] ,$upfile_size 文件大小$_FILES['size'];

 var $new_upfile_name;   # 上传后的文件名称 ;
 var $fleth, $fileExtent; # 文件扩展名(类型) ;
 var $f1, $f2, $f3;   # 文件保存路径(多级) upfiles/2008-01/08/;
 var $filename;    # 文件(带路径) ;
 var $filepath; #相对路径用来删除文件;
 var $maxSize, $File_type; # 允许上传文件的大小 允许上传文件的类型 ;

 var $BuildFile,$newFile,$File_width,$File_height,$rate;

 function upfileclass($upfile,$upfile_name,$upfile_size){
        $this->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;
    }
 }

 

}
?>

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool