一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

php文件上传代码

时间:2010-07-31 编辑:简简单单 来源:一聚教程网

 代码如下 复制代码


 
 
 

/*
 * $name;     上传文件名
 * $size:    上传文件大小
 * $path;     文件原路径
 * $newpath:  设置新路径
 * $not:      禁止上传的文件类型数组
 * $notsize:  限制文件大小的值
 * $move:     上传文件源
 *
 */

class fileupload {
 public $name;
 public $size;
 public $path;
 public $newpath;
 public $not = array();
 public $notsize;
 public $move;
 public $allfile = array();
    function __construct($name,$size,$path,$newpath,$not,$notsize) {
     $this ->name = $name;
     $this ->size = $size/1048576;
     $this ->path = $path;
     $this ->newpath = $newpath;
     $this ->not = explode(',',$not);
     $this ->notsize = $notsize;
        $this ->upload();
    }
    /*
     * 上传程序
     * 首先判断目录是否存在
     * 判断文件类型及大小
     */
    function upload(){
     if(!file_exists($this->newpath)){
      echo "";
      return;
     }else{
            $arr = explode('.',$this->name);
            if(in_array($arr[1],$this->not)){
             echo "";
             return;
            }else if($this->name == ''){
             echo "";
             return;
            }else if($this->size>$this->notsize){
             echo "";
             return;
            }else if(file_exists("$this->newpath"."$this->name")){
                echo "";
                return;
            }
            else{
               $this->move = move_uploaded_file($this->path,$this->newpath.$this->name);
               $this->move();
             }
         }
    }
    /*
     * 判断文件上传是否成功
     */
    function move(){
     if($this->move){
      echo "";
      return;
     }else{
      echo "";
      return;
     }
    }
}


 $fu = new fileupload($array[name],$array[size],$array[tmp_name],'./www.111com.net/','exe,rar',5);

热门栏目