首頁 >後端開發 >php教程 >完整代码演示PHP上传多个文件_PHP教程

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

WBOY
WBOY原創
2016-07-15 13:27:55930瀏覽

前几天看了一本关于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上传多个文件代码实现:

<ol class="dp-xml">
<li class="alt"><span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">php</span></font></strong><span> </span></span></li>
<li class=""><span>require_once("include/upload.class.php");  </span></li>
<li class="alt"><span>if($_POST["button"])  </span></li>
<li class=""><span>{  </span></li>
<li class="alt"><span>//print_r($_FILES);  </span></li>
<li class=""><span>//多个上传  </span></li>
<li class="alt">
<span>//$</span><span class="attribute"><font color="#ff0000">upload</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">newTTRUpload</font></span><span>($_FILES,"ANY");//同下  </span>
</li>
<li class=""><span> </span></li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">upload</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">newTTRUpload</font></span><span>(array($_FILES["file1"],$_FILES["file2"],$_FILES["file3"],$_FILES["file4"]),"ANY");  </span>
</li>
<li class=""><span> </span></li>
<li class="alt"><span>//单个上传  </span></li>
<li class="">
<span>//$</span><span class="attribute"><font color="#ff0000">upload</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">newTTRUpload</font></span><span>($_FILES["file1"]);  </span>
</li>
<li class="alt">
<span>$upload-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>upload();  </span>
</li>
<li class="">
<span>echo$upload-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>getUploadFileName();  </span>
</li>
<li class="alt"><span>}  </span></li>
<li class="">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span>
</li>
<li class="alt">
<span>-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"</span><span class="tag"><strong><font color="#006699">></font></strong></span><span> </span>
</li>
<li class="">
<span></span><span class="tag"><strong><font color="#006699"></font></strong></span><span class="attribute"><font color="#ff0000">htmlxmlns</font></span><span class="tag-name"><strong><font color="#006699">htmlxmlns</font></strong></span><span>=</span><span class="attribute-value"><font color="#0000ff">"http://www.w3.org/1999/xhtml"</font></span><span class="tag"><strong><font color="#006699">></font></strong></span><span> </span>
</li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">head</span><span class="tag">></span></span></font></strong><span> </span>
</li>
<li class="">
<span></span><span class="tag"><strong><font color="#006699"></font></strong></span><span class="attribute"><font color="#ff0000">metahttp-equiv</font></span><span class="tag-name"><strong><font color="#006699">metahttp-equiv</font></strong></span><span>="Content-Type"</span><span class="attribute-value"><font color="#0000ff">content</font></span><span>="text/html;</span><span class="attribute"><font color="#ff0000">charset</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">utf</font></span><span>-8"</span><span class="tag"><strong><font color="#006699">/></font></strong></span><span> </span>
</li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">title</span><span class="tag">></span></span></font></strong><span>UntitledDocument</span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">title</span><span class="tag">></span></font></strong><span> </span>
</li>
<li class="">
<span></span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">head</span><span class="tag">></span></font></strong><span> </span>
</li>
<li class="alt"><span> </span></li>
<li class="">
<span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">body</span><span class="tag">></span></span></font></strong><span> </span>
</li>
<li class="alt">
<span></span><span class="tag"><strong><font color="#006699"></font></strong></span><span class="attribute"><font color="#ff0000">formaction</font></span><span class="tag-name"><strong><font color="#006699">formaction</font></strong></span><span>=""</span><span class="attribute-value"><font color="#0000ff">method</font></span><span>="post"</span><span class="attribute"><font color="#ff0000">enctype</font></span><span>="multipart/form-data"</span><span class="attribute-value"><font color="#0000ff">name</font></span><span>="form1"</span><span class="attribute"><font color="#ff0000">id</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"form1"</font></span><span class="tag"><strong><font color="#006699">></font></strong></span><span> </span>
</li>
<li class="">
<span></span><span class="tag"><strong><font color="#006699"></font></strong></span><span class="attribute"><font color="#ff0000">inputtype</font></span><span class="tag-name"><strong><font color="#006699">inputtype</font></strong></span><span>="file"</span><span class="attribute-value"><font color="#0000ff">name</font></span><span>="file1"</span><span class="attribute"><font color="#ff0000">id</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"file1"</font></span><span class="tag"><strong><font color="#006699">/></font></strong></span><span> </span>
</li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">br</span><span class="tag">/></span></span></font></strong><span> </span>
</li>
<li class="">
<span></span><span class="tag"><strong><font color="#006699"></font></strong></span><span class="attribute"><font color="#ff0000">inputtype</font></span><span class="tag-name"><strong><font color="#006699">inputtype</font></strong></span><span>="file"</span><span class="attribute-value"><font color="#0000ff">name</font></span><span>="file2"</span><span class="attribute"><font color="#ff0000">id</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"file2"</font></span><span class="tag"><strong><font color="#006699">/></font></strong></span><span> </span>
</li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">br</span><span class="tag">/></span></span></font></strong><span> </span>
</li>
<li class="">
<span></span><span class="tag"><strong><font color="#006699"></font></strong></span><span class="attribute"><font color="#ff0000">inputtype</font></span><span class="tag-name"><strong><font color="#006699">inputtype</font></strong></span><span>="file"</span><span class="attribute-value"><font color="#0000ff">name</font></span><span>="file3"</span><span class="attribute"><font color="#ff0000">id</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"file3"</font></span><span class="tag"><strong><font color="#006699">/></font></strong></span><span> </span>
</li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">br</span><span class="tag">/></span></span></font></strong><span> </span>
</li>
<li class="">
<span></span><span class="tag"><strong><font color="#006699"></font></strong></span><span class="attribute"><font color="#ff0000">inputtype</font></span><span class="tag-name"><strong><font color="#006699">inputtype</font></strong></span><span>="file"</span><span class="attribute-value"><font color="#0000ff">name</font></span><span>="file4"</span><span class="attribute"><font color="#ff0000">id</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"file4"</font></span><span class="tag"><strong><font color="#006699">/></font></strong></span><span> </span>
</li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">br</span><span class="tag">/></span></span></font></strong><span> </span>
</li>
<li class="">
<span></span><span class="tag"><strong><font color="#006699"></font></strong></span><span class="attribute"><font color="#ff0000">inputtype</font></span><span class="tag-name"><strong><font color="#006699">inputtype</font></strong></span><span>="submit"</span><span class="attribute-value"><font color="#0000ff">name</font></span><span>="button"</span><span class="attribute"><font color="#ff0000">id</font></span><span>="button"</span><span class="attribute-value"><font color="#0000ff">value</font></span><span>="Submit"</span><span class="tag"><strong><font color="#006699">/></font></strong></span><span> </span>
</li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">form</span><span class="tag">></span></font></strong><span> </span>
</li>
<li class="">
<span></span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">body</span><span class="tag">></span></font></strong><span> </span>
</li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">html</span><span class="tag">></span></font></strong><span> </span>
</li>
<li class=""><span> </span></li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">php</span></font></strong><span> </span>
</li>
<li class=""><span>classTTRUploadextendsError  </span></li>
<li class="alt"><span>{  </span></li>
<li class="">
<span></span><span class="attribute"><font color="#ff0000">constfilesize</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">81200000</font></span><span>;  </span>
</li>
<li class="alt">
<span>private$</span><span class="attribute"><font color="#ff0000">uploadpath</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"uploadfile/"</font></span><span>;  </span>
</li>
<li class="">
<span>private$</span><span class="attribute"><font color="#ff0000">savepath</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">null</font></span><span>;  </span>
</li>
<li class="alt">
<span>private$</span><span class="attribute"><font color="#ff0000">uploadfilename</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">null</font></span><span>;//单个文件为文件名,批量文件为xxxx|xxxx格式,请注意  </span>
</li>
<li class="">
<span>private$</span><span class="attribute"><font color="#ff0000">ext</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">array</font></span><span>("jpg","gif","png");  </span>
</li>
<li class="alt">
<span>private$</span><span class="attribute"><font color="#ff0000">error</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">null</font></span><span>;  </span>
</li>
<li class="">
<span>private$</span><span class="attribute"><font color="#ff0000">file</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">null</font></span><span>;  </span>
</li>
<li class="alt">
<span>private$</span><span class="attribute"><font color="#ff0000">uploadtype</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">null</font></span><span>;  </span>
</li>
<li class="">
<span>private$</span><span class="attribute"><font color="#ff0000">filename</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">null</font></span><span>;  </span>
</li>
<li class="alt"><span> </span></li>
<li class=""><span>//构造函数,$type:ONE单个上传ANY批量上传;  </span></li>
<li class="alt">
<span>publicfunction__construct($file,$</span><span class="attribute"><font color="#ff0000">type</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"ONE"</font></span><span>)  </span>
</li>
<li class=""><span>{  </span></li>
<li class="alt"><span>if($type!="ONE"&&$type!="ANY")  </span></li>
<li class=""><span>{  </span></li>
<li class="alt">
<span>echo"</span><span class="tag"><strong><font color="#006699"></font></strong></span><span class="attribute"><font color="#ff0000">scriptlanguage</font></span><span class="tag-name"><strong><font color="#006699">scriptlanguage</font></strong></span><span>=</span><span class="attribute-value"><font color="#0000ff">'javascript'</font></span><span class="tag"><strong><font color="#006699">></font></strong></span><span>alert('初始化请选择ONE或者ANY')</span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">script</span><span class="tag">></span></font></strong><span>";  </span>
</li>
<li class=""><span>exit;  </span></li>
<li class="alt"><span>}  </span></li>
<li class="">
<span>$this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span class="attribute"><font color="#ff0000">uploadtype</font></span><span>=$type;  </span>
</li>
<li class="alt">
<span>$this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span class="attribute"><font color="#ff0000">file</font></span><span>=$file;  </span>
</li>
<li class=""><span>}  </span></li>
<li class="alt"><span> </span></li>
<li class=""><span>privatefunctioncreateFileName()  </span></li>
<li class="alt"><span>{  </span></li>
<li class="">
<span>return$this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span class="attribute"><font color="#ff0000">filename</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"TTR_"</font></span><span>.time().$this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>getRandomN(4);  </span>
</li>
<li class="alt"><span>}  </span></li>
<li class=""><span> </span></li>
<li class="alt"><span>privatefunctiongetUploadPath()  </span></li>
<li class=""><span>{  </span></li>
<li class="alt">
<span>if(substr($this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>uploadpath,-1,1)!="/")  </span>
</li>
<li class=""><span>{  </span></li>
<li class="alt">
<span>$this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span class="attribute"><font color="#ff0000">savepath</font></span><span>=$this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>uploadpath."/".date("Ym");  </span>
</li>
<li class=""><span>}else{  </span></li>
<li class="alt">
<span>$this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span class="attribute"><font color="#ff0000">savepath</font></span><span>=$this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>uploadpath.date("Ym");  </span>
</li>
<li class=""><span>}  </span></li>
<li class="alt">
<span>$this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span class="attribute"><font color="#ff0000">savepath</font></span><span>=$this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>getFolder($this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>savepath);  </span>
</li>
<li class=""><span>returntrue;  </span></li>
<li class="alt"><span>}  </span></li>
<li class=""><span> </span></li>
<li class="alt"><span>privatefunctiongetFileExt($tempfilename)  </span></li>
<li class=""><span>{  </span></li>
<li class="alt"><span>returnend(explode(".",$tempfilename));  </span></li>
<li class=""><span>}  </span></li>
<li class="alt"><span> </span></li>
<li class=""><span>privatefunctiongetExt()  </span></li>
<li class="alt"><span>{  </span></li>
<li class="">
<span>if(in_array(strtolower($this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>getFileExt($tempfilename)),$this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>ext))  </span>
</li>
<li class="alt"><span>{  </span></li>
<li class=""><span>returntrue;  </span></li>
<li class="alt"><span>}else{  </span></li>
<li class=""><span>returnfalse;  </span></li>
<li class="alt"><span>}  </span></li>
<li class=""><span>}  </span></li>
<li class="alt"><span> </span></li>
<li class=""><span>privatefunctiongetFolder($folder)  </span></li>
<li class="alt"><span>{  </span></li>
<li class=""><span>if(!is_dir($folder))  </span></li>
<li class="alt"><span>{  </span></li>
<li class=""><span>mkdir($folder);  </span></li>
<li class="alt"><span>}  </span></li>
<li class=""><span>return$folder."/";  </span></li>
<li class="alt"><span>}  </span></li>
<li class=""><span> </span></li>
<li class="alt"><span> </span></li>
<li class=""><span>publicfunctionupload()  </span></li>
<li class="alt"><span>{  </span></li>
<li class="">
<span>if($this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span class="attribute"><font color="#ff0000">uploadtype</font></span><span>=="ONE")  </span>
</li>
<li class="alt"><span>{  </span></li>
<li class=""><span> </span></li>
<li class="alt"><span> </span></li>
<li class="">
<span>if($this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>getExt($this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>file["type"]))  </span>
</li>
<li class="alt"><span>{  </span></li>
<li class=""><span> </span></li>
<li class="alt"><span>parent::errorExt();  </span></li>
<li class=""><span> </span></li>
<li class="alt">
<span>}elseif($this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>file["size"]</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>self::filesize){  </span>
</li>
<li class=""><span> </span></li>
<li class="alt"><span>parent::errorFileSize();  </span></li>
<li class=""><span> </span></li>
<li class="alt">
<span>}elseif(!$this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>getUploadPath()){  </span>
</li>
<li class=""><span> </span></li>
<li class="alt"><span>parent::errorUploadPath();  </span></li>
<li class=""><span> </span></li>
<li class="alt"><span>}else{  </span></li>
<li class="">
<span>$</span><span class="attribute"><font color="#ff0000">filenametemp</font></span><span>=$this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>createFileName();  </span>
</li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">filename</font></span><span>=$this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>savepath.$filenametemp.".".$this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>getFileExt($this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>file["name"]);  </span>
</li>
<li class="">
<span>if(move_uploaded_file($this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>file["tmp_name"],$filename))  </span>
</li>
<li class="alt"><span>{  </span></li>
<li class="">
<span>$this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span class="attribute"><font color="#ff0000">uploadfilename</font></span><span>=$filenametemp;  </span>
</li>
<li class="alt"><span>parent::okMoved();  </span></li>
<li class=""><span> </span></li>
<li class="alt"><span> </span></li>
<li class=""><span>}else{  </span></li>
<li class="alt"><span>parent::errorMoveUpload();  </span></li>
<li class=""><span>}  </span></li>
<li class="alt"><span>}  </span></li>
<li class="">
<span>}elseif($this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span class="attribute"><font color="#ff0000">uploadtype</font></span><span>=="ANY"){  </span>
</li>
<li class="alt"><span> </span></li>
<li class="">
<span>for($</span><span class="attribute"><font color="#ff0000">i</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">0</font></span><span>;$i</span><strong><font color="#006699"><span class="tag"><span class="tag-name">count</span></span></font></strong><span>($this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>file);$i++)  </span>
</li>
<li class="alt"><span>{  </span></li>
<li class=""><span> </span></li>
<li class="alt">
<span>if($this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>getExt($this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>file[$i]["type"]))  </span>
</li>
<li class=""><span>{  </span></li>
<li class="alt"><span>parent::errorExt();  </span></li>
<li class=""><span> </span></li>
<li class="alt">
<span>}elseif($this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>file[$i]["size"]</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>self::filesize){  </span>
</li>
<li class=""><span> </span></li>
<li class="alt"><span>parent::errorFileSize();  </span></li>
<li class=""><span> </span></li>
<li class="alt">
<span>}elseif(!$this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>getUploadPath()){  </span>
</li>
<li class=""><span> </span></li>
<li class="alt"><span>parent::errorUploadPath();  </span></li>
<li class=""><span> </span></li>
<li class="alt"><span>}else{  </span></li>
<li class="">
<span>$</span><span class="attribute"><font color="#ff0000">filenametemp</font></span><span>=$this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>createFileName();  </span>
</li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">filename</font></span><span>=$this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>savepath.$filenametemp.".".$this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>getFileExt($this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>file[$i]["name"]);  </span>
</li>
<li class="">
<span>if(move_uploaded_file($this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>file[$i]["tmp_name"],$filename))  </span>
</li>
<li class="alt"><span>{  </span></li>
<li class="">
<span>$</span><span class="attribute"><font color="#ff0000">str.</font></span><span>=$filenametemp."|";  </span>
</li>
<li class="alt"><span> </span></li>
<li class=""><span>}else{  </span></li>
<li class="alt"><span>parent::errorMoveUpload();  </span></li>
<li class=""><span>}  </span></li>
<li class="alt"><span> </span></li>
<li class=""><span>}  </span></li>
<li class="alt"><span> </span></li>
<li class=""><span>}  </span></li>
<li class="alt">
<span>$this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span class="attribute"><font color="#ff0000">uploadfilename</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">substr</font></span><span>($str,0,strlen($str)-1);  </span>
</li>
<li class=""><span>parent::okMoved();  </span></li>
<li class="alt"><span>}  </span></li>
<li class=""><span>}  </span></li>
<li class="alt"><span> </span></li>
<li class=""><span>publicfunctiongetUploadFileName()  </span></li>
<li class="alt"><span>{  </span></li>
<li class="">
<span>return$this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>uploadfilename;  </span>
</li>
<li class="alt"><span>}  </span></li>
<li class=""><span> </span></li>
<li class="alt"><span>publicfunctionsetUploadPath($path)  </span></li>
<li class=""><span>{  </span></li>
<li class="alt">
<span>$this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span class="attribute"><font color="#ff0000">uploadpath</font></span><span>=$path;  </span>
</li>
<li class=""><span>}  </span></li>
<li class="alt"><span> </span></li>
<li class=""><span> </span></li>
<li class="alt"><span>privatefunctiongetRandomN($n)  </span></li>
<li class=""><span>{  </span></li>
<li class="alt">
<span>if($n</span><strong><font color="#006699"><span class="tag"><span class="tag-name">1</span></span></font></strong><span>||$n</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>10)return"";  </span>
</li>
<li class=""><span> </span></li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">ary_num</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">array</font></span><span>(0,1,2,3,4,5,6,7,8,9);  </span>
</li>
<li class="">
<span>$</span><span class="attribute"><font color="#ff0000">return</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">""</font></span><span>;  </span>
</li>
<li class="alt">
<span>for($</span><span class="attribute"><font color="#ff0000">i</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">0</font></span><span>;$i</span><span class="tag"><strong><font color="#006699"></font></strong></span><span>$n;$i++)  </span>
</li>
<li class=""><span>{  </span></li>
<li class="alt">
<span>$</span><span class="attribute-value"><font color="#0000ff">rand</font></span><span class="attribute"><font color="#ff0000">randn</font></span><span>=rand(0,9-$i);  </span>
</li>
<li class="">
<span>$</span><span class="attribute"><font color="#ff0000">return.</font></span><span>=$ary_num[$randn];  </span>
</li>
<li class="alt"><span>$ary_num[$randn]=$ary_num[9-$i];  </span></li>
<li class=""><span>}  </span></li>
<li class="alt"><span>return$return;  </span></li>
<li class=""><span>}  </span></li>
<li class="alt"><span> </span></li>
<li class=""><span> </span></li>
<li class="alt"><span> </span></li>
<li class=""><span>publicfunction__destruct()  </span></li>
<li class="alt"><span>{  </span></li>
<li class="">
<span>$this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span class="attribute"><font color="#ff0000">uploadfilename</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">null</font></span><span>;  </span>
</li>
<li class="alt">
<span>$this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span class="attribute"><font color="#ff0000">uploadtype</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">null</font></span><span>;  </span>
</li>
<li class="">
<span>$this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span class="attribute"><font color="#ff0000">file</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">null</font></span><span>;  </span>
</li>
<li class="alt">
<span>$this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span class="attribute"><font color="#ff0000">savepath</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">null</font></span><span>;  </span>
</li>
<li class=""><span>}  </span></li>
<li class="alt"><span> </span></li>
<li class=""><span>}  </span></li>
<li class="alt"><span> </span></li>
<li class=""><span>classError  </span></li>
<li class="alt"><span>{  </span></li>
<li class=""><span>publicstaticfunctionerrorFileSize()  </span></li>
<li class="alt"><span>{  </span></li>
<li class=""><span>echo"超出最大上传限制";  </span></li>
<li class="alt"><span>}  </span></li>
<li class=""><span> </span></li>
<li class="alt"><span>publicstaticfunctionerrorExt()  </span></li>
<li class=""><span>{  </span></li>
<li class="alt"><span>echo"此类文件不允许上传";  </span></li>
<li class=""><span>}  </span></li>
<li class="alt"><span> </span></li>
<li class=""><span>publicstaticfunctionerrorUploadPath()  </span></li>
<li class="alt"><span>{  </span></li>
<li class=""><span>echo"上传路径不正确";  </span></li>
<li class="alt"><span>}  </span></li>
<li class=""><span> </span></li>
<li class="alt"><span>publicstaticfunctionerrorMoveUpload()  </span></li>
<li class=""><span>{  </span></li>
<li class="alt"><span>echo"上传失败";  </span></li>
<li class=""><span>}  </span></li>
<li class="alt"><span> </span></li>
<li class=""><span>publicstaticfunctionokMoved()  </span></li>
<li class="alt"><span>{  </span></li>
<li class=""><span>echo"上传成功!";  </span></li>
<li class="alt"><span>}  </span></li>
<li class=""><span> </span></li>
<li class="alt"><span>publicstaticfunctionokArrayMoved()  </span></li>
<li class=""><span>{  </span></li>
<li class="alt"><span>echo"上传成功!";  </span></li>
<li class=""><span>} </span></li>
</ol>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/446489.htmlTechArticle前几天看了一本关于PHP的书,让我感触很深,我先介绍一下PHP的发展史,然后在教大家一个PHP上传多个文件的一个小技巧。让我们先来简单...
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn