好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

文件上传php代码 - php上传下载

文件上传php代码

这是一款使用方便简单的php文件上传函数,只你要设置三个参数就可以方便的把你指定的文件类型上传批指定的目录了,代码如下:

function  upfile( $filename , $type , $path )  {      $tempfile = $_files [ $filename ]; //接收上传的临时文件       //有没有上传成功     if ( $error = $tempfile [ "error" ])   {     switch ( $error ){      case  1: $errorstr = "上传的文件超过了2m请返回检查。" ; break ;      case  2: $errorstr = "上传文件的大小超过了 html 表单中限定值8m" ; break ;      case  3: $errorstr = "文件只有部分被上传" ; break ;      case  4: $errorstr = "没有文件被上传" ; break ;      case  6: $errorstr = "找不到临时文件夹" ; break ;      case  7: $errorstr = "文件写入失败" ; break ;    }    showmsg( $errorstr );   }      //文件类型是否在允许的范围内     $filename = $tempfile [ "name" ]; //取上传原文件名     $tmparr = explode ( "." , $filename );    $extname = strtolower ( $tmparr [ count ( $tmparr )-1]); //取出原扩展名并转为小写字母     if (!in_array( $extname , $type )) showmsg( "上传的文件类型不允许,请返回检查." );      //改文件名     $newfile = "zy" .time().rand(100,1000). "." . $extname ; //构成新的文件名       //路径     $path .= $newfile ;      //重名判断     if ( file_exists ( $path )){     $newfile = "zy" .time().rand(100,1000). "." . $extname ; //构成新的文件名      $path .= $newfile ;   }      if (!move_uploaded_file( $tempfile [ 'tmp_name' ], $path ))showmsg( "文件移动失败。" );      return   $newfile ;  } //开源代码phpfensi.com     //上传函数调用方法,代码如下:     upfile( $filename , $type , $path );  /*  参数:  $filename   为上传表单 type=file的名称  $type  允许上传的文件类型  $path  保存到文件路径  

查看更多关于文件上传php代码 - php上传下载的详细内容...

  阅读:57次