您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關PHP中怎么利用上傳類實現單個和批量上傳,文章內容質量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。
PHP上傳類代碼:
<?php /** *@packagemyFrameworkuploadclass *@Descriptionuploadclass *@Date2007-11-28 *@authorantsnet *@copyrighthttp://www.antsnet.net *@Emailantsnet@163.com *@Environment:Apache2.0.59+PHP5.2.5+mysql5.0 *@version$Id:myFrame_Upload.php22008-02-2701:14:05ZAdministrator$ */ classmyFrame_UploadextendsmyFrame { var$uploadPath="uploadFile/"; var$fullPath=''; var$message; var$_debug=false; var$errorMessage=''; function__construct($uploadPath='') { if($uploadPath!="") { $this->uploadPath=$uploadPath; } } /** *Batchupload * *@paramArray$arrayOutPut */ publicfunctionformLocalBatch($keepSource=false,$arrayOutPut='') { $returnArray=array(); if(sizeof($_FILES)==$arrayOutPut&&!$keepSource) { $i=0; foreach($_FILESas$index=>$value) { $returnArray[]=$this->fromLocal($value,$outPutName[$i]); $i++; } }else{ foreach($_FILESas$index=>$value) { $returnArray[]=$this->fromLocal($value); } } return$returnArray; } /** *Uploadfileformlocal * *@paramArray|String$file_Area_Name *@paramArray|String$outPutName */ publicfunctionfromLocal($VALUE,$outPutName='') { include_once(SERVERROOT.MYFRAME.'myFrame_Basic.php'); /** *thefollowingforsingle */ if($outPutName==''||$outPutName=="NULL") { $outPutName=date("YmdHis"); } if($VALUE['error']>0) { switch($VALUE['errror']) { case'1': $this->errorMessage[]=$this->myFrameMessage['false']['file']['max']; returnfalse; break; case'2': $this->errorMessage[]=$this->myFrameMessage['false']['file']['maxDefined']; returnfalse; break; case'3': $this->errorMessage[]=$this->myFrameMessage['false']['file']['uncomplite']; returnfalse; break; case'4': $this->errorMessage[]=$this->myFrameMessage['false']['file']['unupload']; returnfalse; break; } } $fileName=$this->uploadPath.$outPutName.myFrame_Basic::getFileName($VALUE['name']).myFrame_Basic::getFileExt($VALUE['name']); if(is_uploaded_file($VALUE['tmp_name'])) { if(!move_uploaded_file($VALUE['tmp_name'],$fileName)) { $this->errorMessage[]=$this->myFrameMessage['false']['file']['move']; returnfalse; }else{ return$fileName; } } } /** *Uploadfromnetwork * *@paramArray|String$url *@paramArray|String$outPutName *@paramBool$keepSource */ publicfunctionfromNet($url,$outPutName='',$keepSource=false) { include_once(SERVERROOT.MYFRAME.'myFrame_Basic.php'); if($outPutName=="") { $outPutName=date("YmdHis"); } $fileType=myFrame_Basic::getFileExt($url); $fileName=$outPutName.$fileType; $contents=file_get_contents($url); $return=file_put_contents($this->uploadPath.$fileName,$contents); if($return){ $this->fullPath=$this->uploadPath.$fileName; return$this->fullPath; }else{ $this->errorMessage[]=$this->myFrameMessage['false']['file']['url']; returnfalse; } } }
關于PHP中怎么利用上傳類實現單個和批量上傳就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。