The PHP upload class is quite commonly used, so I studied the PHP upload class and shared it with you here. I hope it will be useful to everyone. PHP itself is a simple yet powerful language. The PHP language has core features such as powerful string and array processing capabilities, and has greatly improved support for object-oriented programming (PHP5 and above).
PHP upload class code:
<ol class="dp-xml"> <li class="alt"><span><span class="tag"><?</SPAN><SPAN class=tag-name>php</SPAN><SPAN> </SPAN></SPAN><LI class=""><SPAN>/** </SPAN><LI class=alt><SPAN>*@packagemyFrameworkuploadclass </SPAN><LI class=""><SPAN>*@Descriptionuploadclass </SPAN><LI class=alt><SPAN>*@Date2007-11-28 </SPAN><LI class=""><SPAN>*@authorantsnet </SPAN><LI class=alt><SPAN>*@copyrighthttp://www.antsnet.net </SPAN><LI class=""><SPAN>*@Emailantsnet@163.com </SPAN><LI class=alt><SPAN>*@Environment:Apache2.0.59+PHP5.2.5+mysql5.0 </SPAN><LI class=""><SPAN>*@version$Id:myFrame_Upload.php22008-02-2701:14:05ZAdministrator$ </SPAN><LI class=alt><SPAN>*/ </SPAN><LI class=""><SPAN>classmyFrame_UploadextendsmyFrame </SPAN><LI class=alt><SPAN>{ </SPAN><LI class=""><SPAN>var$</SPAN><SPAN class=attribute>uploadPath</SPAN><SPAN>=</SPAN><SPAN class=attribute-value>"uploadFile/"</SPAN><SPAN>; </SPAN></SPAN><LI class=alt><SPAN>var$</SPAN><SPAN class=attribute>fullPath</SPAN><SPAN>=</SPAN><SPAN class=attribute-value>''</SPAN><SPAN>; </SPAN></SPAN><LI class=""><SPAN>var$message; </SPAN><LI class=alt><SPAN>var$</SPAN><SPAN class=attribute>_debug</SPAN><SPAN>=</SPAN><SPAN class=attribute-value>false</SPAN><SPAN>; </SPAN></SPAN><LI class=""><SPAN>var$</SPAN><SPAN class=attribute>errorMessage</SPAN><SPAN>=</SPAN><SPAN class=attribute-value>''</SPAN><SPAN>; </SPAN></SPAN><LI class=alt><SPAN> </SPAN><LI class=""><SPAN>function__construct($</SPAN><SPAN class=attribute>uploadPath</SPAN><SPAN>=</SPAN><SPAN class=attribute-value>''</SPAN><SPAN>) </SPAN></SPAN><LI class=alt><SPAN>{ </SPAN><LI class=""><SPAN>if($uploadPath!="") </SPAN><LI class=alt><SPAN>{ </SPAN><LI class=""><SPAN>$this-</SPAN><SPAN class=tag>></span><span class="attribute">uploadPath</span><span>=$uploadPath; </span></span></li> <li class="alt"><span>} </span></li> <li class=""><span>} </span></li> <li class="alt"><span>/** </span></li> <li class=""><span>*Batchupload </span></li> <li class="alt"><span>* </span></li> <li class=""><span>*@paramArray$arrayOutPut </span></li> <li class="alt"><span>*/ </span></li> <li class=""> <span>publicfunctionformLocalBatch($</span><span class="attribute">keepSource</span><span>=</span><span class="attribute-value">false</span><span>,$</span><span class="attribute">arrayOutPut</span><span>=</span><span class="attribute-value">''</span><span>) </span> </li> <li class="alt"><span>{ </span></li> <li class=""> <span>$</span><span class="attribute">returnArray</span><span>=</span><span class="attribute-value">array</span><span>(); </span> </li> <li class="alt"><span>if(sizeof($_FILES)==$arrayOutPut&&!$keepSource) </span></li> <li class=""><span>{ </span></li> <li class="alt"> <span>$</span><span class="attribute">i</span><span>=</span><span class="attribute-value">0</span><span>; </span> </li> <li class=""> <span>foreach($_FILESas$</span><span class="attribute">index</span><span>=</span><span class="tag">></span><span>$value) </span> </li> <li class="alt"><span>{ </span></li> <li class=""> <span>$returnArray[]=$this-</span><span class="tag">></span><span>fromLocal($value,$outPutName[$i]); </span> </li> <li class="alt"><span>$i++; </span></li> <li class=""><span>} </span></li> <li class="alt"><span>}else{ </span></li> <li class=""> <span>foreach($_FILESas$</span><span class="attribute">index</span><span>=</span><span class="tag">></span><span>$value) </span> </li> <li class="alt"><span>{ </span></li> <li class=""> <span>$returnArray[]=$this-</span><span class="tag">></span><span>fromLocal($value); </span> </li> <li class="alt"><span>} </span></li> <li class=""><span>} </span></li> <li class="alt"><span>return$returnArray; </span></li> <li class=""><span>} </span></li> <li class="alt"><span>/** </span></li> <li class=""><span>*Uploadfileformlocal </span></li> <li class="alt"><span>* </span></li> <li class=""><span>*@paramArray|String$file_Area_Name </span></li> <li class="alt"><span>*@paramArray|String$outPutName </span></li> <li class=""><span>*/ </span></li> <li class="alt"> <span>publicfunctionfromLocal($VALUE,$</span><span class="attribute">outPutName</span><span>=</span><span class="attribute-value">''</span><span>) </span> </li> <li class=""><span>{ </span></li> <li class="alt"><span> </span></li> <li class=""><span>include_once(SERVERROOT.MYFRAME.'myFrame_Basic.php'); </span></li> <li class="alt"><span>/** </span></li> <li class=""><span>*thefollowingforsingle </span></li> <li class="alt"><span>*/ </span></li> <li class=""> <span>if($</span><span class="attribute">outPutName</span><span>==''||$</span><span class="attribute">outPutName</span><span>=="NULL") </span> </li> <li class="alt"><span>{ </span></li> <li class=""> <span>$</span><span class="attribute">outPutName</span><span>=</span><span class="attribute-value">date</span><span>("YmdHis"); </span> </li> <li class="alt"><span>} </span></li> <li class=""> <span>if($VALUE['error']</span><span class="tag">></span><span>0) </span> </li> <li class="alt"><span>{ </span></li> <li class=""><span>switch($VALUE['errror']) </span></li> <li class="alt"><span>{ </span></li> <li class=""><span>case'1': </span></li> <li class="alt"> <span>$this-</span><span class="tag">></span><span>errorMessage[]=$this-</span><span class="tag">></span><span>myFrameMessage['false']['file']['max']; </span> </li> <li class=""><span>returnfalse; </span></li> <li class="alt"><span>break; </span></li> <li class=""><span>case'2': </span></li> <li class="alt"> <span>$this-</span><span class="tag">></span><span>errorMessage[]=$this-</span><span class="tag">></span><span>myFrameMessage['false']['file']['maxDefined']; </span> </li> <li class=""><span>returnfalse; </span></li> <li class="alt"><span>break; </span></li> <li class=""><span>case'3': </span></li> <li class="alt"> <span>$this-</span><span class="tag">></span><span>errorMessage[]=$this-</span><span class="tag">></span><span>myFrameMessage['false']['file']['uncomplite']; </span> </li> <li class=""><span>returnfalse; </span></li> <li class="alt"><span>break; </span></li> <li class=""><span>case'4': </span></li> <li class="alt"> <span>$this-</span><span class="tag">></span><span>errorMessage[]=$this-</span><span class="tag">></span><span>myFrameMessage['false']['file']['unupload']; </span> </li> <li class=""><span>returnfalse; </span></li> <li class="alt"><span>break; </span></li> <li class=""><span> </span></li> <li class="alt"><span>} </span></li> <li class=""><span>} </span></li> <li class="alt"> <span>$</span><span class="attribute">fileName</span><span>=$this-</span><span class="tag">></span><span>uploadPath.$outPutName.myFrame_Basic::getFileName($VALUE['name']).myFrame_Basic::getFileExt($VALUE['name']); </span> </li> <li class=""><span>if(is_uploaded_file($VALUE['tmp_name'])) </span></li> <li class="alt"><span>{ </span></li> <li class=""><span>if(!move_uploaded_file($VALUE['tmp_name'],$fileName)) </span></li> <li class="alt"><span>{ </span></li> <li class=""> <span>$this-</span><span class="tag">></span><span>errorMessage[]=$this-</span><span class="tag">></span><span>myFrameMessage['false']['file']['move']; </span> </li> <li class="alt"><span>returnfalse; </span></li> <li class=""><span>}else{ </span></li> <li class="alt"><span>return$fileName; </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>*Uploadfromnetwork </span></li> <li class="alt"><span>* </span></li> <li class=""><span>*@paramArray|String$url </span></li> <li class="alt"><span>*@paramArray|String$outPutName </span></li> <li class=""><span>*@paramBool$keepSource </span></li> <li class="alt"><span>*/ </span></li> <li class=""> <span>publicfunctionfromNet($url,$</span><span class="attribute">outPutName</span><span>=</span><span class="attribute-value">''</span><span>,$</span><span class="attribute">keepSource</span><span>=</span><span class="attribute-value">false</span><span>) </span> </li> <li class="alt"><span>{ </span></li> <li class=""><span>include_once(SERVERROOT.MYFRAME.'myFrame_Basic.php'); </span></li> <li class="alt"> <span>if($</span><span class="attribute">outPutName</span><span>=="") </span> </li> <li class=""><span>{ </span></li> <li class="alt"> <span>$</span><span class="attribute">outPutName</span><span>=</span><span class="attribute-value">date</span><span>("YmdHis"); </span> </li> <li class=""><span>} </span></li> <li class="alt"> <span>$</span><span class="attribute">fileType</span><span>=</span><span class="attribute-value">myFrame_Basic</span><span>::getFileExt($url); </span> </li> <li class=""> <span>$</span><span class="attribute">fileName</span><span>=$outPutName.$fileType; </span> </li> <li class="alt"> <span>$</span><span class="attribute">contents</span><span>=</span><span class="attribute-value">file_get_contents</span><span>($url); </span> </li> <li class=""> <span>$</span><span class="attribute">return</span><span>=</span><span class="attribute-value">file_put_contents</span><span>($this-</span><span class="tag">></span><span>uploadPath.$fileName,$contents); </span> </li> <li class="alt"><span>if($return){ </span></li> <li class=""> <span>$this-</span><span class="tag">></span><span class="attribute">fullPath</span><span>=$this-</span><span class="tag">></span><span>uploadPath.$fileName; </span> </li> <li class="alt"> <span>return$this-</span><span class="tag">></span><span>fullPath; </span> </li> <li class=""><span>}else{ </span></li> <li class="alt"> <span>$this-</span><span class="tag">></span><span>errorMessage[]=$this-</span><span class="tag">></span><span>myFrameMessage['false']['file']['url']; </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> </ol>