php 支持多文件上传
分类:热门资源

?php/***TTR上传类*2007-09-22*[url=][/url]*QQ:252319874**/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){echoscriptlanguage='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||$n10)return;$ary_num=array(0,1,2,3,4,5,6,7,8,9);$return=;for($i=0;$i$n;$i++){$randn=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上传成功!;}}实例应用:

?phprequire_once(include/upload.class.php);if($_POST[button]){//print_r($_FILES);//多个上传$upload=newTTRUpload(array($_FILES[file1],$_FILES[file2],$_FILES[file3],$_FILES[file4]),ANY);//单个上传//$upload=newTTRUpload($_FILES[file1]);$upload-upload();echo$upload-getUploadFileName();}?!DOCTYPEhtmlPUBLIC-//W3C//DTDXHTML1.0Transitional//EN;charset=utf-8/titleUntitledDocument/title/headbodyformaction=method=postenctype=multipart/form-dataname=form1id=form1inputtype=filename=file1id=file1/br/inputtype=filename=file2id=file2/br/inputtype=filename=file3id=file3/br/inputtype=filename=file4id=file4/br/inputtype=submitname=buttonid=buttonvalue=Submit//form/body/html

本文由威尼斯在线注册平台发布于热门资源,转载请注明出处:php 支持多文件上传

上一篇:(每页展现数量卡塔尔(قطر‎ $sql='select count( 下一篇:我们就使用PHPLib提供的数据库类
猜你喜欢
热门排行
精彩图文