PHP Upload class implements single and batch upload. PHP Upload classes are quite common, so I studied the PHP Upload class and shared it with you here. I hope it will be useful to you. PHP itself is a simple and powerful language, and PHP Upload class is quite common. so I studied the PHP Upload class and shared it with you here. I hope it will be useful to you. PHP itself is a simple and powerful language. PHP has core features such as powerful string and array processing capabilities, and greatly improved support for object-oriented programming (PHP5 and later versions ).
Using standard and optional extension modules, PHP applications can connect to more than a dozen databases such as MySQL or Oracle, draw, create PDF files, and create parsed XML files. You can also use the C language to write your own PHP extension module. For example, provide a PHP interface function in an existing code library. You can also run PHP in Windows, use COM to control other Windows applications such as Word and Excel, or use ODBC to connect to the database. In China, PHP is a commonly used network programming language.
PHP Upload code:
- 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;
- }
- }
- }
Bytes. PHP itself is a simple and powerful language...