温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

PHP中怎么利用上传类实现单个和批量上传

发布时间:2021-06-30 15:04:55 来源:亿速云 阅读:141 作者:Leah 栏目:编程语言

这篇文章将为大家详细讲解有关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中怎么利用上传类实现单个和批量上传就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php
AI