论坛里查了一下,也找不到完整的上传文件案例那位高人可以提供一下案例代码

解决方案 »

  1.   

    给出一个最简单的代码吧:
    <?php
    set_time_limit(0);
    if ($_POST['action']=="uppic"){
    $upfile=&$HTTP_POST_FILES['pic'];
    $upfileEx=substr($upfile['name'],-3);
    $pic='./'.date("YmdGhis").'.'.$upfileEx;//上传目录+用时间当文件名+后缀
    $upTemp=move_uploaded_file($upfile['tmp_name'],$pic);
    chmod($pic, 0755);//设定上传的文件的属性
    if ($upTemp){
    //上传成功
    }else{
    //上传失败
    }
    }
    ?>
    <form action="" method="post" enctype="multipart/form-data" name="form1">
      <input name="pic" type="file" id="pic">
      <input type="submit" name="Submit" value="提交">
      <input name="action" type="hidden" id="action" value="uppic">
    </form>
    给出一个学习PHP文件上传的链接:http://tech.ccidnet.com/art/3089/20080626/1489677_1.html
      

  2.   

    代码是在网上找的,在windows主机上面可以执行。linux主机下可能会存在问题。那就看看这篇文章吧:
    http://www.w3school.com.cn/php/php_file_upload.asp
      

  3.   

    PHP官方网上有很多现成的例子,应该多看看文档,这样求助实在有点重复
      

  4.   

    lz下载手册,搜索一下$_FILE,里面有文件上传的例子
    《PHP中文版开发手册[CHM]适合PHP4/PHP5》
      

  5.   

    简单的一个函数,多的就是一个类,呵呵,看看手册吧,
    [/img]
      

  6.   

    最好的例子是php帮助文档,以下代码摘自php帮助文档,上传时表单的enctype="multipart/form-data",php上传最大文件限制可以修改php.ini文件控制<form action="" method="post" enctype="multipart/form-data">
    <p>Pictures:
    <input type="file" name="pictures[]" />
    <input type="file" name="pictures[]" />
    <input type="file" name="pictures[]" />
    <input type="submit" value="Send" />
    </p>
    </form> 
    <?php
    foreach ($_FILES["pictures"]["error"] as $key => $error) {
        if ($error == UPLOAD_ERR_OK) {
            $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
            $name = $_FILES["pictures"]["name"][$key];
            move_uploaded_file($tmp_name, "data/$name");
        }
    }
    ?>  
      

  7.   

    判断文件类型,生成随机命名,上传,每句代码都有注释,而且代码都做了测试,可以拿来直接用....ps:用的时候别忘了建upload文件夹,否则会报错,至于判断并自动创建文件夹的功能..lz自己办了吧..-_-# 箱底都翻烂了....]
    <form action="upload_final_verC.php" method="post" enctype="multipart/form-data">
      <input type="file" name="file" />
      <input type="submit" value="提交" />
    </form>[code=PHP
    <?php
    //print_r($_FILES);//debug:输出提交过的$_FILES数据
    //调用函数
    Upload($_FILES);
    ?>
    <?php
    /**
    * 生成随机数
    * 参数:$length 长度
    * 返回值: $length长度的随机字符 如upfile_s5mfGpBdbk
    **/
    function random($length){
    //文件名前缀
    $hash = 'upfile_'; 
    //随机字符列表,可自由修改
    $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
    //字符串最大值,mt_rand()第二参数
    $max = strlen($chars) - 1;
    //用当前时间戳随机播种,此函数可省略,只用mt_rand()即可达到使用要求
    //mt_srand((double)microtime() * 1000000);
        
    //根据$length参数决定随机字符数
    for($i = 0; $i < $length; $i++){
    //获取一个随机数
         $hash .= $chars[mt_rand(0, $max)];
                //var_dump($hash);     //debug:$hash值
           }
         //var_dump($hash);     //debug:$hash值
         //返回随机字符
         return $hash;
    }/**
    * 文件上传
    * 参数:$file($_FILE超全局变量)
    * 返回:图片相对地址(插入数据库)
    **/
    function Upload($files){
    //允许上传文件类型
    $type = array("jpg","jpeg","gif","bmp","png");
    //上传路径
    $path = "./upload/";
    //获取上传文件后缀
    $ftype = strtolower(substr(strrchr($files["file"]["name"], '.'), 1));  
    //检查文件类型
    if(!in_array($ftype,$type)){//不通过则执行
    $types=implode(",",$type);
    echo "您只能上传以下类型文件: ",$types,"<br>";
    return false;
    }else{//通过则执行
    //判断文件大小
    if($files["file"]["size"] > 2000000){
    echo "文件过大,已超过2MB";
    return false;
    }else{//文件大小符合标准,则执行
    //执行循环,获取不重复的随机文件名
    do{
    //获取一个新随机文件名
    $fname = random(10).".".$ftype;
    //上传路径+文件名
    $upfile = $path.$fname;
    //判断此文件名是否被占用,若没有则跳出循环,重复则重新生成
    }while(file_exists($upfile));

    //上传文件
    if(move_uploaded_file($files["file"]["tmp_name"],$upfile)){
    //下面这句应该是你最想看的 ;)
    var_dump($upfile);
    //成功则返回数组
        return $upfile;
    }else{
    return false;
    }
       }
    }
    return false;
    }
    ?>
    [/code]
      

  8.   

    [code=PHP
    <?php
    //print_r($_FILES);//debug:输出提交过的$_FILES数据
    //调用函数
    Upload($_FILES);
    ?>
    <?php
    /**
    * 生成随机数
    * 参数:$length 长度
    * 返回值: $length长度的随机字符 如upfile_s5mfGpBdbk
    **/
    function random($length){
    //文件名前缀
    $hash = 'upfile_'; 
    //随机字符列表,可自由修改
    $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
    //字符串最大值,mt_rand()第二参数
    $max = strlen($chars) - 1;
    //用当前时间戳随机播种,此函数可省略,只用mt_rand()即可达到使用要求
    //mt_srand((double)microtime() * 1000000);
        
    //根据$length参数决定随机字符数
    for($i = 0; $i < $length; $i++){
    //获取一个随机数
         $hash .= $chars[mt_rand(0, $max)];
                //var_dump($hash);     //debug:$hash值
           }
         //var_dump($hash);     //debug:$hash值
         //返回随机字符
         return $hash;
    }/**
    * 文件上传
    * 参数:$file($_FILE超全局变量)
    * 返回:图片相对地址(插入数据库)
    **/
    function Upload($files){
    //允许上传文件类型
    $type = array("jpg","jpeg","gif","bmp","png");
    //上传路径
    $path = "./upload/";
    //获取上传文件后缀
    $ftype = strtolower(substr(strrchr($files["file"]["name"], '.'), 1));  
    //检查文件类型
    if(!in_array($ftype,$type)){//不通过则执行
    $types=implode(",",$type);
    echo "您只能上传以下类型文件: ",$types,"<br>";
    return false;
    }else{//通过则执行
    //判断文件大小
    if($files["file"]["size"] > 2000000){
    echo "文件过大,已超过2MB";
    return false;
    }else{//文件大小符合标准,则执行
    //执行循环,获取不重复的随机文件名
    do{
    //获取一个新随机文件名
    $fname = random(10).".".$ftype;
    //上传路径+文件名
    $upfile = $path.$fname;
    //判断此文件名是否被占用,若没有则跳出循环,重复则重新生成
    }while(file_exists($upfile));

    //上传文件
    if(move_uploaded_file($files["file"]["tmp_name"],$upfile)){
    //下面这句应该是你最想看的 ;)
    var_dump($upfile);
    //成功则返回数组
        return $upfile;
    }else{
    return false;
    }
       }
    }
    return false;
    }
    ?>
    [/code]
      

  9.   

    要是再不好...我就把浏览器吃了....-_-#<?php 
    //print_r($_FILES);//debug:输出提交过的$_FILES数据 
    //调用函数 
    Upload($_FILES); 
    ?> 
    <?php 
    /** 
    * 生成随机数 
    * 参数:$length 长度 
    * 返回值: $length长度的随机字符 如upfile_s5mfGpBdbk 
    **/ 
    function random($length){ 
      //文件名前缀 
      $hash = 'upfile_'; 
      //随机字符列表,可自由修改 
      $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz'; 
      //字符串最大值,mt_rand()第二参数 
      $max = strlen($chars) - 1; 
      //用当前时间戳随机播种,此函数可省略,只用mt_rand()即可达到使用要求 
      //mt_srand((double)microtime() * 1000000); 
        
      //根据$length参数决定随机字符数 
      for($i = 0; $i < $length; $i++){ 
        //获取一个随机数 
        $hash .= $chars[mt_rand(0, $max)]; 
        //var_dump($hash);    //debug:$hash值 
      } 
      //var_dump($hash);    //debug:$hash值 
      //返回随机字符 
      return $hash; 
    } /** 
    * 文件上传 
    * 参数:$file($_FILE超全局变量) 
    * 返回:图片相对地址(插入数据库) 
    **/ 
    function Upload($files){ 
      //允许上传文件类型 
      $type = array("jpg","jpeg","gif","bmp","png"); 
      //上传路径 
      $path = "./upload/"; 
      //获取上传文件后缀 
      $ftype = strtolower(substr(strrchr($files["file"]["name"], '.'), 1));  
      //检查文件类型 
      if(!in_array($ftype,$type)){//不通过则执行 
        $types=implode(",",$type); 
        echo "您只能上传以下类型文件: ",$types," <br>"; 
        return false; 
      }else{//通过则执行 
          //判断文件大小 
          if($files["file"]["size"] > 2000000){ 
            echo "文件过大,已超过2MB"; 
            return false; 
          }else{//文件大小符合标准,则执行 
            //执行循环,获取不重复的随机文件名 
            do{ 
              //获取一个新随机文件名 
              $fname = random(10).".".$ftype; 
              //上传路径+文件名 
              $upfile = $path.$fname; 
              //判断此文件名是否被占用,若没有则跳出循环,重复则重新生成 
            }while(file_exists($upfile));         //上传文件 
            if(move_uploaded_file($files["file"]["tmp_name"],$upfile)){ 
              //下面这句应该是你最想看的 ;) 
              var_dump($upfile); 
              //成功则返回数组 
              return $upfile; 
            }else{ 
              return false; 
          } 
        } 
      } 
      return false; 

    ?> 
      

  10.   


    顶一下~~~
    哈哈~~~~~~~~~~~~~~~~~
    绝对正确的code!
    多用print_r();测试下~~~
      

  11.   

    /**
     *FileUpload_Single:单个文件上传类 
     *Files_Upload:批量上传类
     *Files_Upload_Crt 上传证书,与私钥
     *批量上传使用方法:
     *     $tmp = new Files_Upload;
     *     $tmp -> accessPath = "userfiles/".$newmailrandid ;
     *     $tmp -> fileSize = 50 ; //int 300KB (单个大小)
     *     $tmp -> iAllSize = 10000;
     *     $tmp -> defineTypeList = "asp|php|exe";
     *     $tmp -> filePrefix = "way";
     *     $tmp -> changNameMode = null;
     *     $tmp -> file_id = "attfile";
     *     $tmp -> TODO();
     *单个文件上传使用方法
     *     $tmp = new FileUpload_Single_SA;
     *     $tmp -> accessPath = "../userfiles/" ;
     *     $tmp -> fileSize = 5000 ;
     *     if ( $tmp -> TODO() ){}..
     */
     
    ////////////////////////////////////////////////////////////////////////////
    //上传证书,与私钥
    ///////////////////////////////////////////////////////////////////////////
    class Files_Upload_Crt
    {
    //user define ------------------------------------- 
    var $accessPath ;  //string "./" is current
    var $fileSize;  //int 300KB
    var $defineTypeList; //string jpg|gif|bmp  ...
    var $filePrefix; //string
    var $changNameMode; //chang name mode value: 0-2 ,NULL:不改名
    var $file_id;
    var $iAllSize;        //允许上传的最大附件
    var $errno; // 错误代号//------------------------------------------------- 
    var $uploadFiles; //array upload file attribute 
    var $newFileName = array(); //array
    var $error = array(); //array
    var $fileType = array(); //array
    var $fileNameArr = array(); //定义文件名数组array
      
    function TODO(){ //函数入口
    $this -> GetAttri();
    $pass = true ;

    if (!$this -> MoveFileToNewPath() ){
    $pass = false;
    }

    return $pass;

    } //得到文件
    function GetAttri()//1
    {
    $this -> fileType = explode( "|" , $this -> defineTypeList ); //禁用的文件类型
    $this -> uploadFiles = @$_FILES[$this -> file_id]; //上传文件的文件数组


     
      //移动文件
    function MoveFileToNewPath()
    {
    $i = 0;
    if ($this -> CheckAllSize()){ //检查所有附件与允许上传的附件大小
    foreach( $this -> uploadFiles[ "name" ] as $v ){ //循环文件名
    if ( $v != NULL ){
    if ( $this -> CheckType( $v ) ){
    $newFileName = $this -> makePassword(5).$this -> uploadFiles[ 'name' ][ $i ];//在文件名前加上5位随机数
    if ( file_exists( $this -> accessPath ) ){
    if ( move_uploaded_file ($this -> uploadFiles[ "tmp_name" ][ $i ] , realpath( $this -> accessPath ) . "/" . $newFileName ) )
    {
    //函数用于在一个数组的末尾插入一个或多个元素。
    array_push( $this -> newFileName, $newFileName );
    }else{
    return false;
    }
    }

    }else{
    return false;
    }
    }
    $i++; 

    }

    }else{
    return false;
    }

    if ( $i == 0 ){ 
    return false;
    }else{
    return true;
    }

    }
     
      //检查文件类型
    function CheckType( $uploadName  )
    {
    if ( in_array( substr( $uploadName ,  strrpos( $uploadName , "." ) + 1 , strlen( $uploadName ) - strrpos( $uploadName , "." ) ) , $this->fileType ) )
    {
    return false;
    }
    else
    {
    return true;
    }
    }
     
    //检查文件大小
    function CheckSize( $fileSize )
    {
    return $fileSize > $this -> fileSize * 1024;
    }

    //允许上传的总大小进行判断
    function CheckAllSize(){
    $iTempSize = 0;
    foreach($this -> uploadFiles["size"] as $isize){
    $iTempSize += $isize;
    }
    if($iTempSize > $this -> iAllSize * 1024 ){
    return false;
    }else{
    return true;
    }

    }

    //在文件名前加上5位随机数
    function makePassword($maxLen){
    $strNewPass = "";
    for($i = 1; $i<=$maxLen; $i++ ){
    $whatsNext = rand(0, 1);
    if($whatsNext == 0){
    $upper = 90;
    $lower = 65;
    }else{
    $upper = 57;
    $lower = 48;
    }
    $iNum = intval(rand(0, (intval($upper - $lower)))) + $lower;
    $strChar = chr($iNum);
    $strNewPass = $strNewPass.$strChar;
    }
    return $strNewPass;
    }
    }/////////////////////////////////////////////////////////////////////////////////
    //简单文件上传
    ////////////////////////////////////////////////////////////////////////////////
    class FileUpload_Single_SA
    {
    //user define ------------------------------------- 
    var $accessPath ;    //string "./" is current 文件所接收的路径
    var $fileSize;       //int 300KB
    var $defineTypeList; //string jpg|gif|bmp  ...
    var $filePrefix;     //string 上传之后在文件前面所加的字符串
    var $changNameMode;  //chang name mode value: 0-2 ,NULL:不改名
     
    //------------------------------------------------- 
    var $uploadFile;     //array upload file attribute 
    var $newFileName;    //上传完成之后新的文件名
    var $error;
     
     
    function TODO()  //主调函数
    {  
    $this -> error = "<ul>";
    $pass = true ;
     
    if ( ! $this -> GetFileAttri() ) //检查是否有文件上传
    {
    $this -> error .= "<li>The file doesn't exist.</li>";
    //return false;
    $pass = false;
    }

      
    if( ! $this -> CheckFileAttri_size() )
    {
    $this -> error .= "<li>The file uploaded is too big.</li>";
    return false;
    $pass = false;
    }  
    if ( ! $this -> MoveFileToNewPath() )
    {
    $this -> error .= "<li>error, the file has been moved.</li>";
    //return false;
    $pass = false;
    }  
    $this -> error .= "</ul>";
    return $pass;

    /*--------------------------------------------------*/
     
      //检查是否有文件上传 没有返回false
    function GetFileAttri()

    foreach( $_FILES as $tmp )//当前单元的值被赋给 $tmp,数组内部的指针向前移一步
    {
    $this -> uploadFile = $tmp; //$tmp为当前临时文件数组
    }
    return ( empty( $this -> uploadFile[ 'name' ] ) ) ? false : true;
    }
     
      //检查文件大小,fileSize为规定的大小
    function CheckFileAttri_size()
    {
    if ( ! empty ( $this -> fileSize ) )
    {
    if ( is_numeric( $this -> fileSize ) )
    {
    if ( $this -> fileSize > 0 )
    {
    //上传的文件大小与规定大小进行比较
    return ( $this -> uploadFile[ 'size' ] > $this -> fileSize * 1024 ) ? false : true ;
    }   
    }
    else
    {
    return false;
    }
    }
    else
    {
    return false;
    }
    }
     
      //移动文件到新的目录
    function MoveFileToNewPath()
    {
    $newFileName = "MuseMailRbl.txt";

    if ( file_exists( $this -> accessPath ) )
    {
    if ( move_uploaded_file( $this -> uploadFile[ 'tmp_name' ] , realpath( $this -> accessPath ) . "/" . $newFileName ) )
    {
    $this -> newFileName = $newFileName;
    return true;
    }
    else
    {
    return false;
    }
    }
    else
    {
    return false;
    }
    } }
      

  12.   

    ///////////////////////////////////////////////////////////////////////////////////////////
    //简单文件上传
    //////////////////////////////////////////////////////////////////////////////////////////
    class FileUpload_Single
    {
    //user define ------------------------------------- 
    var $accessPath ;    //string "./" is current 文件所接收的路径
    var $fileSize;       //int 300KB
    var $defineTypeList; //string jpg|gif|bmp  ...
    var $filePrefix;     //string 上传之后在文件前面所加的字符串
    var $changNameMode;  //chang name mode value: 0-2 ,NULL:不改名
     
    //------------------------------------------------- 
    var $uploadFile;     //array upload file attribute 
    var $newFileName;    //上传完成之后新的文件名
    var $error;
     
     
    function TODO()  //主调函数
    {  
    $this -> error = "<ul>";
    $pass = true ;
     
    if ( ! $this -> GetFileAttri() )
    {
    $this -> error .= "<li>The file doesn't exist.</li>";
    //return false;
    $pass = false;
    }

      
    if( ! $this -> CheckFileAttri_size() )
    {
    $this -> error .= "<li>The file uploaded is too big.</li>";
    return false;
    $pass = false;
    }/*
    if( ! $this -> CheckFileMIMEType() )
    {
    $this -> error .= "<li>The file type is incorrect.</li>";
    //return false;
    $pass = false;

    */
      
    if ( ! $this -> MoveFileToNewPath() )
    {
    $this -> error .= "<li>error, the file has been moved.</li>";
    //return false;
    $pass = false;
    }  
    $this -> error .= "</ul>";
    return $pass;

    /*--------------------------------------------------*/
     
      //检查是否有文件上传 没有返回false
    function GetFileAttri()

    foreach( $_FILES as $tmp )//当前单元的值被赋给 $tmp,数组内部的指针向前移一步
    {
    $this -> uploadFile = $tmp; //$tmp为当前临时文件数组
    }
    return ( empty( $this -> uploadFile[ 'name' ] ) ) ? false : true;
    }
     
      //检查文件大小,fileSize为规定的大小
    function CheckFileAttri_size()
    {
    if ( ! empty ( $this -> fileSize ) )
    {
    if ( is_numeric( $this -> fileSize ) )
    {
    if ( $this -> fileSize > 0 )
    {
    //上传的文件大小与规定大小进行比较
    return ( $this -> uploadFile[ 'size' ] > $this -> fileSize * 1024 ) ? false : true ;
    }   
    }
    else
    {
    return false;
    }
    }
    else
    {
    return false;
    }
    }
     
     
      //文件更名
    function ChangeFileName ( $prefix = NULL  , $mode )
    {// string $prefix , int $mode 文件更名函数

    $fullName = ( isset( $prefix ) ) ? $prefix."_" : NULL ;
    switch ( $mode )
    {
    case 0   : $fullName .= rand( 0 , 100 ). "_" .strtolower( date ("ldSfFYhisa") ) ; break;
    case 1   : $fullName .= rand( 0 , 100 ). "_" .time(); break;
    case 2   : $fullName .= rand( 0 , 10000 ) . time();   break;
    case NULL : $fullName = NULL;break;
    default  : $fullName .= rand( 0 , 10000 ) . time();   break;
    }
    return $fullName;
    }
     
      //移动文件到新的目录
    function MoveFileToNewPath()
    {
    $newFileName = NULL;
    if ( $this -> changNameMode != NULL )
    {
    $newFileName = $this -> ChangeFileName( $this -> filePrefix , $this -> changNameMode ). "." . $this -> GetFileTypeToString();
    }
    else
    {
    $newFileName = $this -> uploadFile[ 'name' ];
    }

    if ( file_exists( $this -> accessPath ) )
    {
    if ( file_exists( $this -> accessPath . $newFileName ) )
    {
    $newFileName = uniqid("")."_" . $newFileName; //uniqid函数基于以微秒计的当前时间,生成一个唯一的 ID
    //echo "<script>alert('目标目录存在同名文件,因此已把上传的文件改名为:$newFileName.');</script>";
    }
    if ( move_uploaded_file( $this -> uploadFile[ 'tmp_name' ] , realpath( $this -> accessPath ) . "/" . $newFileName ) )
    {
    $this -> newFileName = $newFileName;
    return true;
    }
    else
    {
    return false;
    }
    }
    else
    {
    return false;
    }

     
     
    function CheckFileExist( $path = NULL )
    {
    return ( $path == NULL ) ? false : ( ( file_exists( $path ) ) ? true : false );
    }
     
      //得到上传文件的类型
    function GetFileMIME()
    {
    return empty( $this -> uploadFile[ 'type' ] ) ? NULL : $this -> uploadFile[ 'type' ] ;
    } //检查上传的文件类型是不是被禁用的
    function CheckFileMIMEType()
    {
    $pass = false;
    $defineTypeList = strtolower( $this -> defineTypeList ); //禁止上传的文件类型
    $MIME = strtolower( $this -> GetFileMIME() ); //得到上传文件的文件类型
    if ( !empty ( $defineTypeList ) )
    {
    if ( !empty ( $MIME ) )
    {
    foreach( explode( "|" , $MIME ) as $tmp ) //explode()将一个字符串以数组的形式打散
    {
      if ( $tmp == $MIME )
    {
      $pass = false;
    }

    }
    }
    else
    {
    return true;
    }     
    }
    else
    {
    return true;
    }
    return $pass;
    }
     
      //截取,得到文件后缀
    function GetFileTypeToString()
    {
    if( ! empty( $this -> uploadFile[ 'name' ] ) )
    {
    return substr( strtolower( $this -> uploadFile[ 'name' ] ) , strlen( $this -> uploadFile[ 'name' ] ) - 3 , 3 ); 
    }
    }
     
    }
      

  13.   

    ///////////////////////////////////////////////////////////////////////////////////
    //批量上传类
    //////////////////////////////////////////////////////////////////////////////////
    class Files_Upload
    {
    //暂时不用,考虑到别的操作系统可以识别的文件类型差异,需要调试
    /**
    $fileType[ "exe" ] = "application/octet-stream";
    $fileType[ "gif" ] = "image/gif";
    $fileType[ "jpg" ] = "image/pjpeg";
    $fileType[ "png" ] = "image/x-png";
    $fileType[ "bmp" ] = "image/bmp"; 
    $fileType[ "txt" ] = "text/plain";
    $fileType[ "html" ] = "text/plain";
    $fileType[ "doc" ] = "application/msword";
    $fileType[ "xls" ] = "application/vnd.ms-excel";
    $fileType[ "ppt" ] = "application/vnd.ms-powerpoint"; $tmp = new Files_Upload;
    $tmp -> accessPath = "bk/" ;
    $tmp -> fileSize = 50 ;//int 300KB
    $tmp -> defineTypeList = "jpeg|jpg|gif";//string jpg|gif|bmp  ...
    $tmp -> filePrefix = "way";//string
    $tmp -> changNameMode = 2;
    $tmp -> file_id = "file";//文件域id[], eg.file[]
    $tmp -> TODO();
    **/
     
    //user define ------------------------------------- 
    var $accessPath ;  //string "./" is current
    var $fileSize;  //int 300KB
    var $defineTypeList; //string jpg|gif|bmp  ...
    var $filePrefix; //string
    var $changNameMode; //chang name mode value: 0-2 ,NULL:不改名
    var $file_id;
    var $iAllSize;        //允许上传的最大附件
    var $errno; // 错误代号//------------------------------------------------- 
    var $uploadFiles; //array upload file attribute 
    var $newFileName = array(); //array
    var $error = array(); //array
    var $fileType = array(); //array
    var $fileNameArr = array(); //定义文件名数组array
    var $OldAttFileName = array();
    var $NewAttFileName = array();
      
    function TODO()
    {
    $this->errno = 0;
    $this -> GetAttri();
    $this -> MoveFileToNewPath();
    } //文件更名函数
    function ChangeFileName ( $prefix = NULL  , $mode )
    {// string $prefix , int $mode
    $fullName = ( isset( $prefix ) ) ? $prefix."_" : NULL ;
    switch ( $mode )
    {
    case 0   : $fullName .= rand( 0 , 100 ). "_" .strtolower( date ("ldSfFYhisa") ) ; break;
    case 1   : $fullName .= rand( 0 , 100 ). "_" .time(); break;
    case 2   : $fullName .= rand( 0 , 10000000 ) . time();   break;
    case NULL : $fullName = NULL;break;
    default  : $fullName .= rand( 0 , 10000 ) . time();   break;
    }
    return $fullName;
    } //得到文件类型
    function GetAttri()//1
    {
    $this -> fileType = explode( "|" , $this -> defineTypeList ); //禁用的文件类型
    $this -> uploadFiles = @$_FILES[$this -> file_id]; //上传文件的文件数组

     
    //移动文件夹move_uploaded_file( iconv("gb2312", "UTF-8", $file["tmp_name"]), $path); 
    function MoveFileToNewPath()
    {
    $i = 0;
    if ($this -> CheckAllSize()){ //检查所有附件与允许上传的附件大小

    foreach( $this -> uploadFiles[ "name" ] as $v ){ //循环文件名
    if ( $v != NULL ){

    if ( $this -> CheckType( $v ) ){
    $newFileName = NULL;
    if ( $this -> changNameMode != NULL ){
    $newFileName = $this -> ChangeFileName( $this -> filePrefix , $this -> changNameMode ). "." . substr( $v ,  strrpos( $v , "." ) + 1 , strlen( $v ) - strrpos( $v , "." ) ) ;
    }else{
    $newFileName = $this -> uploadFiles[ 'name' ][ $i ];
    } if ( file_exists( $this -> accessPath ) ){
    if ( file_exists( $this -> accessPath . $newFileName ) ){
    $newFileName = uniqid("")."_" . $newFileName;
    $this->errno = 1;
    }
    //$newFileName = iconv("UTF-8","GBK",$newFileName);
    if ( move_uploaded_file ($this -> uploadFiles[ "tmp_name" ][ $i ] , realpath( $this -> accessPath ) . "/" . $newFileName ) )
    {
    array_push( $this -> newFileName, $newFileName );
    $this -> OldAttFileName[$i] = $this -> uploadFiles[ 'name' ][ $i ];
    $this -> NewAttFileName[$i] = $newFileName; }else{
    $this->errno = 3;
    }

    }

    }else{
    $this->errno = 2;
    } }
    $i++; 
    }
    }
    if ( $i == 0 ) { return false;}

    }
     
      //检查文件类型
    function CheckType( $uploadName  )
    {
    if ( in_array( substr( $uploadName ,  strrpos( $uploadName , "." ) + 1 , strlen( $uploadName ) - strrpos( $uploadName , "." ) ) , $this->fileType ) )
    {
    return false;
    }
    else
    {
    return true;
    }
    }
     
    //检查文件大小
    function CheckSize( $fileSize )
    {
    return $fileSize > $this -> fileSize * 1024;
    }

    //允许上传的总大小进行判断
    function CheckAllSize(){
    $iTempSize = 0;
    foreach($this -> uploadFiles["size"] as $isize){
    $iTempSize += $isize;
    }
    //echo "a=$iTempSize";
    if($iTempSize > $this -> iAllSize * 1024 ){
    return false;
    }else{
    return true;
    }

    }// 批量删除文件
    // @param $fileName 所要删除的文件名: 格式:"126.css`a.txt`x.txt`test.txt"
    function delfile($fileNameTemp){
    //echo $fileNameTemp;
    $this -> fileNameArr = explode( "`" , $fileNameTemp );
    var_dump($this -> fileNameArr);
    $i = count($this -> fileNameArr);
    $Rnt = 1;
    foreach($this -> fileNameArr as $fileNameValue){
    //echo $fileNameValue."<br>";
    if(!@unlink($fileNameValue))
    $Rnt = 0; 
    else
    $Rnt = 1; 
    }
    if($Rnt == 1){
    return true;
    }else{
    return false;
    }

    }

    // 得到错误信息
    function errmsg(){
    $uploadClassError = array(
    0 =>'文件上传成功. ',
    1 =>'目标目录存在同名文件,因些已把上传的文件改名.',
    2 =>'文件类型不匹配.',
    3 =>'文件不能移到目标位置. ',
    4 =>'文件删除不功能. ',
    );
    if ($this->errno == 0)
    return false;
    else
    return $uploadClassError[$this->errno];
    }