PHP上傳類實(shí)現(xiàn)單個(gè)和批量上傳
PHP上傳類還是比較常用的,于是我研究了一下PHP上傳類,在這里拿出來和大家分享一下,希望對(duì)大家有用。PHP本身是一種簡(jiǎn)單而強(qiáng)大的語言。PHP語言擁有核心特性如強(qiáng)大的字符串和數(shù)組處理能力,同時(shí)極大的改進(jìn)了對(duì)面向?qū)ο缶幊痰闹С郑≒HP5以上版本)。
#T#通過使用標(biāo)準(zhǔn)的和可選的擴(kuò)展模塊,PHP應(yīng)用程序可以連接MySQL或Oracle等十幾種數(shù)據(jù)庫、繪圖、創(chuàng)建PDF文件和創(chuàng)建解析XML文件。你也可以使用C語言來寫自己的PHP擴(kuò)展模塊。例如,在已存在的代碼庫中提供一個(gè)PHP的接口函數(shù)。你也可以在Windows下運(yùn)行PHP,使用COM控制其它諸如Word和Excel的Windows應(yīng)用程序,或者使用ODBC來連接數(shù)據(jù)庫。在國(guó)內(nèi),PHP曾經(jīng)和微軟的ASP并駕齊驅(qū),是大家常用的網(wǎng)絡(luò)編程語言?!?/P>
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;
- }
- }
- }