您好,欢迎访问一九零五行业门户网

完整代码演示PHP上传多个文件_PHP教程

前几天看了一本关于php的书,让我感触很深,我先介绍一下php的发展史,然后在教大家一个php上传多个文件的一个小技巧。让我们先来简单的介绍一下php吧!php 最初是1994年rasmus lerdorf创建的,刚刚开始只是一个简单的用perl语言编写的程序,用来统计他自己网站的访问者。后来又用c语言重新编写,包括可以访问数据库。
以后越来越多的网站使用了php,并且强烈要求增加一些特性,比如循环语句和数组变量等等,在新的成员加入开发行列之后,在1995年 中,php2.0发布了。第二版定名为php/fi(form interpreter)。php/fi加入了对msql的支持,从此建立了php在动态网页开发上的地位。到了1996年底,有15000个网站使用 php/fi;时间到了1997年中,使用php/fi的网站数字超过五万个。而在1997年中,开始了第三版的开发计划,开发小组加入了 zeev suraski 及 andi gutmans,而第三版就定名为php3。2000年,php4.0又问世了,其中增加了许多新的特性。以下给大家介绍一个php上传多个文件的方法。php上传多个文件代码实现:
php require_once(include/upload.class.php);  if($_post[button])  {  //print_r($_files);  //多个上传  //$upload=newttrupload($_files,any);//同下   $upload=newttrupload(array($_files[file1],$_files[file2],$_files[file3],$_files[file4]),any);   //单个上传  //$upload=newttrupload($_files[file1]);  $upload->upload();  echo$upload->getuploadfilename();  }  ?> -//w3c//dtdxhtml1.0transitional//enhttp://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd> htmlxmlnshtmlxmlns=http://www.w3.org/1999/xhtml> head> metahttp-equivmetahttp-equiv=content-typecontent=text/html;charset=utf-8/> title>untitleddocumenttitle> head>  body> formactionformaction=method=postenctype=multipart/form-dataname=form1id=form1> inputtypeinputtype=filename=file1id=file1/> br/> inputtypeinputtype=filename=file2id=file2/> br/> inputtypeinputtype=filename=file3id=file3/> br/> inputtypeinputtype=filename=file4id=file4/> br/> inputtypeinputtype=submitname=buttonid=buttonvalue=submit/> form> body> html>  php classttruploadextendserror  {  constfilesize=81200000;  private$uploadpath=uploadfile/;  private$savepath=null;  private$uploadfilename=null;//单个文件为文件名,批量文件为xxxx|xxxx格式,请注意  private$ext=array(jpg,gif,png);  private$error=null;  private$file=null;  private$uploadtype=null;  private$filename=null;   //构造函数,$type:one单个上传any批量上传;  publicfunction__construct($file,$type=one)  {  if($type!=one&&$type!=any)  {  echoscriptlanguagescriptlanguage='javascript'>alert('初始化请选择one或者any')script>;  exit;  }  $this->uploadtype=$type;  $this->file=$file;  }   privatefunctioncreatefilename()  {  return$this->filename=ttr_.time().$this->getrandomn(4);  }   privatefunctiongetuploadpath()  {  if(substr($this->uploadpath,-1,1)!=/)  {  $this->savepath=$this->uploadpath./.date(ym);  }else{  $this->savepath=$this->uploadpath.date(ym);  }  $this->savepath=$this->getfolder($this->savepath);  returntrue;  }   privatefunctiongetfileext($tempfilename)  {  returnend(explode(.,$tempfilename));  }   privatefunctiongetext()  {  if(in_array(strtolower($this->getfileext($tempfilename)),$this->ext))  {  returntrue;  }else{  returnfalse;  }  }   privatefunctiongetfolder($folder)  {  if(!is_dir($folder))  {  mkdir($folder);  }  return$folder./;  }    publicfunctionupload()  {  if($this->uploadtype==one)  {    if($this->getext($this->file[type]))  {   parent::errorext();   }elseif($this->file[size]>self::filesize){   parent::errorfilesize();   }elseif(!$this->getuploadpath()){   parent::erroruploadpath();   }else{  $filenametemp=$this->createfilename();  $filename=$this->savepath.$filenametemp...$this->getfileext($this->file[name]);  if(move_uploaded_file($this->file[tmp_name],$filename))  {  $this->uploadfilename=$filenametemp;  parent::okmoved();    }else{  parent::errormoveupload();  }  }  }elseif($this->uploadtype==any){   for($i=0;$icount($this->file);$i++)  {   if($this->getext($this->file[$i][type]))  {  parent::errorext();   }elseif($this->file[$i][size]>self::filesize){   parent::errorfilesize();   }elseif(!$this->getuploadpath()){   parent::erroruploadpath();   }else{  $filenametemp=$this->createfilename();  $filename=$this->savepath.$filenametemp...$this->getfileext($this->file[$i][name]);  if(move_uploaded_file($this->file[$i][tmp_name],$filename))  {  $str.=$filenametemp.|;   }else{  parent::errormoveupload();  }   }   }  $this->uploadfilename=substr($str,0,strlen($str)-1);  parent::okmoved();  }  }   publicfunctiongetuploadfilename()  {  return$this->uploadfilename;  }   publicfunctionsetuploadpath($path)  {  $this->uploadpath=$path;  }    privatefunctiongetrandomn($n)  {  if($n1||$n>10)return;   $ary_num=array(0,1,2,3,4,5,6,7,8,9);  $return=;  for($i=0;$i$n;$i++)  {  $randrandn=rand(0,9-$i);  $return.=$ary_num[$randn];  $ary_num[$randn]=$ary_num[9-$i];  }  return$return;  }     publicfunction__destruct()  {  $this->uploadfilename=null;  $this->uploadtype=null;  $this->file=null;  $this->savepath=null;  }   }   classerror  {  publicstaticfunctionerrorfilesize()  {  echo超出最大上传限制;  }   publicstaticfunctionerrorext()  {  echo此类文件不允许上传;  }   publicstaticfunctionerroruploadpath()  {  echo上传路径不正确;  }   publicstaticfunctionerrormoveupload()  {  echo上传失败;  }   publicstaticfunctionokmoved()  {  echo上传成功!;  }   publicstaticfunctionokarraymoved()  {  echo上传成功!;  } 
http://www.bkjia.com/phpjc/446489.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/446489.htmltecharticle前几天看了一本关于php的书,让我感触很深,我先介绍一下php的发展史,然后在教大家一个php上传多个文件的一个小技巧。让我们先来简单...
其它类似信息

推荐信息