\n
      \n\n\n\n\n\n\n\n\n\n\n<\/form>\n<\/body>\n<\/html>\n\n<\/pre>\n\n

      更多關于PHP相關內容感興趣的讀者可查看本站專題:《php文件操作總結》、《PHP運算與運算符用法總結》、《PHP網(wǎng)絡編程技巧總結》、《PHP基本語法入門教程》、《php操作office文檔技巧總結(包括word,excel,access,ppt)》、《php日期與時間用法總結》、《php面向對象程序設計入門教程》、《php字符串(string)用法總結》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》<\/p>\n

      希望本文所述對大家PHP程序設計有所幫助。<\/p>\n

      <\/p>\n

      \nhttp:\/\/www.bkjia.com\/PHPjc\/1123792.html<\/span>www.bkjia.com<\/span>true<\/span>http:\/\/www.bkjia.com\/PHPjc\/1123792.html<\/span>TechArticle<\/span>PHP實現(xiàn)的多文件上傳類及用法示例, 本文實例講述了PHP實現(xiàn)的多文件上傳類及用法。分享給大家供大家參考,具體如下: 1、upFiles.css.php...<\/span>\n<\/div>\n
      <\/div>\n"}

      国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

      目錄
      PHP實現(xiàn)的多文件上傳類及用法示例,
      首頁 后端開發(fā) php教程 PHP實現(xiàn)的多文件上傳類及用法示例,_PHP教程

      PHP實現(xiàn)的多文件上傳類及用法示例,_PHP教程

      Jul 12, 2016 am 08:53 AM
      php 多文件上傳

      PHP實現(xiàn)的多文件上傳類及用法示例,

      本文實例講述了PHP實現(xiàn)的多文件上傳類及用法。分享給大家供大家參考,具體如下:

      1、upFiles.css.php 文件

      <&#63;php
      class UploadFiles{
       private $maxsize = '1000000'; //允許上傳文件最大長度
       private $allowtype = array('jpg','png','gif','jpeg');//允許上傳文件類型
       private $israndfile = true;//是否隨機文件名
       private $filepath;//上傳路徑
       private $originName;//上傳的源文件
       private $tmpfileName;//臨時文件名
       private $newfileName;//新文件名
       private $fileSize;//文件大小
       private $fileType;//文件類型
       private $errorNum = 0;//錯誤號
       private $errorMessg = array();//錯誤消息
       //對成員初始化
       function __construct($options = array()){
       foreach($options as $key=>$val){
        $key = strtolower($key);
        //查看傳進來的數(shù)組里下標是否與成員屬性相同
        //print_r(array_keys(get_class_vars(get_class($this))));
        if(!in_array($key,array_keys(get_class_vars(get_class($this))))){
        continue;
        }else{
        $this->setOption($key,$val);
        }
       }
       }
       private function setOption($key,$val){
         $this->$key = $val;
       //echo $this->errorNum."<br>";
       }
       //檢查文件上傳路徑
       private function checkfilePath(){
       //echo $this->filepath;
       if(empty($this->filepath)){
        $this->setOption('errorNum',"-5");
        return false;
       }
       if(!file_exists($this->filepath) || !is_writable($this->filepath)){
        if(!@mkdir($this->filepath,0755)){
        $this->setOption('errorNum','-4');
        return false;
        }
       }
       return true;
       }
       //獲取錯誤信息
       private function getError(){
       $str = "上傳文件{$this->originName}出錯---";
       switch($this->errorNum){
        case 4; $str .= "沒有文件被上傳";break;
        case 3; $str .= "文件只被部分上傳";break;
        case 2; $str .= "超過文件表單允許大小";break;
        case 1; $str .= "超過php.ini中允許大小";break;
        case -1; $str .= "未允許的類型";break;
        case -2; $str .= "文件過大,不能超過".$this->maxsize."個字節(jié)";break;
        case -3; $str .= "上傳失敗";break;
        case -4; $str .= "建立文件上傳目錄失敗";break;
        case -5; $str .= "必須指定上傳路徑";break;
        default; $str .= "未知錯誤";
       }
       return $str."<br>";
       }
       //檢查文件類型
       private function checkfileType(){
       //echo $this->fileType;
       if(!in_array(strtolower($this->fileType),$this->allowtype)){
       $this->setOption('errorNum','-1');
        return false;
       }else{
        return true;
       }
       }
       //檢查文件大小
       private function checkfileSize(){
       if($this->fileSize > $this->maxsize){
        $this->setOption('errorNum','-2');
        return false;
       }else{
        return true;
       }
       }
       //處理隨機文件名稱
       private function prorandFile(){
       $ch = $this->israndfile;
       if($ch == 'true'){
        return true;
       }else{
        return false;
       }
       }
       //
       private function setFiles($name="",$tmp_name="",$size="",$error=""){
       //檢查上傳路徑
       if(!$this->checkfilePath()){
        //$this->errorMessg = $this->getError();
        return false;
       }
       //echo $error."<br>";
       if($error){
       $this->setOption('errorNum',$error);
        return false;
       }
       $arrstr  = explode('.',$name);
       $type   = end($arrstr);
       $this->setOption('originName',$name);
       $this->setOption('fileSize',$size);
       $this->setOption('fileType',$type);
       $this->setOption('tmpfileName',$tmp_name);
       return true;
       }
       //檢查是否有文件上傳
       function checkFile($formname){
       if(!@$_FILES[$formname]){
        $this->setOption('errorNum',4);
        return false;
       }else{
        return true;
       }
       }
       //上傳文件
       function uploadeFile($formname){
       if(!$this->checkFile($formname)){
        $this->errorMessg = $this->getError();
        return false;
       }
       $return  = true;
       $name   = @$_FILES[$formname]['name'];
       $tmp_name = @$_FILES[$formname]['tmp_name'];
       $size   = @$_FILES[$formname]['size'];
       $error  = @$_FILES[$formname]['error'];
       //$type   = $_FILES[$formname]['type'];
       if(is_array($name)){
        $errors = array();
        for($i=0; $i<count($name); $i++){
        if($this->setFiles($name[$i],$tmp_name[$i],$size[$i],$error[$i])){
         if(!$this->checkfileSize() || !$this->checkfileType()){
         $errors[] = $this->getError();
         $return = false;
         }
        }else{
         $errors[] = $this->getError();
         $return = false;
        }
        if(!$return) $this->setFiles();
        }
        if($return){
        $newfileN = array();
        for($i=0; $i<count($name); $i++){
         if($this->setFiles($name[$i],$tmp_name[$i],$size[$i],$error[$i])){
         if(!$this->copyFile()){
          $errors[] = $this->getError();
          $return = false;
         }else{
          $newfileN[] = $this->newfileName;
         }
         }
         $this->newfileName = $newfileN;
        }
        }
        //print_r($errors);
        $this->errorMessg = $errors;
        //echo $errors;
        return $return;
       }else{
        if($this->setFiles($name,$tmp_name,$size,$error)){
        $return = true;
        if($error) var_dump($error);
        if($this->checkfileSize() && $this->checkfileType()){
        }else{
         $return = false;
        }
        }else{
        $return = false;
        }
        if(!$return){
        $this->errorMessg = $this->getError();
        }
        return $return;
       }
       }
       //獲取上傳后的文件名
       function getnewFile(){
        return $this->newfileName;
       }
       //把文件拷貝到指定的路徑
       function copyFile(){
       $filepath = rtrim($this->filepath,'/')."/";
       if(!$this->errorNum){
        if($this->prorandFile()){
         $this->newfileName = date('Ymdhis').rand(1000,9999).".".$this->fileType;
        }else{
         $this->newfileName = $this->originName;
        }
        if(!move_uploaded_file($this->tmpfileName,$filepath.$this->newfileName)){
        $this->setOption('errorNum',-3);
        return false;
        }else{
        return true;
        }
       }else{
        return false;
       }
       }
       //上傳錯誤后返回的消息
       function gteerror(){
        $err = $this->errorMessg;
       return $err;
       }
       }
      &#63;>
      
      

      2、使用方法

      uploade.php 文件:

      <&#63;php
      //print_r($_FILES['spic']);
      header('Content-Type:text/html;charset=utf-8');
      //if(@$_FILES['spic'])echo "ddddddddd";;
      include('upFiles.css.php');
      $upfile = new UploadFiles(array('filepath'=>'./upload','allowtype'=>array('php','bmp','gif','jpg','png'),'israndfile'=>true,'maxsize'=>'1000000'));
      if($upfile ->uploadeFile('spic')){
       $arrfile = $upfile ->getnewFile();
       foreach($arrfile as $v){
       echo $v,"<br/>";
       }
       echo "上傳成功!";
      }else{
       $err = $upfile ->gteerror();
       if(is_array($err)){
       foreach($err as $v1){
        echo $v1,"<br/>";
       }
       }else{
       echo $err;
       }
       //var_dump($err);
      }
      //var_dump($upfile);
      &#63;>
      
      

      HTML 文件:

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>無標題文檔</title>
      <script type="text/javascript">
      function Check(){
       //alert('dddd');
       for(i=1; i<9; i++){
       if(document.getElementById('v'+i).value == ''){
        document.getElementById('v'+i).name = 'uu';
       }
       }
      }
      </script>
      </head>
      <body>
      <form name="upfile" action="uploade.php" method="post" enctype="multipart/form-data">
      <input type="file" name="spic[]" id="v1" /><br/>
      <input type="file" name="spic[]" id="v2" /><br/>
      <input type="file" name="spic[]" id="v3" /><br/>
      <input type="file" name="spic[]" id="v4" /><br/>
      <input type="file" name="spic[]" id="v5" /><br/>
      <input type="file" name="spic[]" id="v6" /><br/>
      <input type="file" name="spic[]" id="v7" /><br/>
      <input type="file" name="spic[]" id="v8" /><br/>
      <input type="submit" name="sub" value="提交" onclick="return Check()" />
      <input type="reset" name="res" value="重填" />
      </form>
      </body>
      </html>
      
      

      更多關于PHP相關內容感興趣的讀者可查看本站專題:《php文件操作總結》、《PHP運算與運算符用法總結》、《PHP網(wǎng)絡編程技巧總結》、《PHP基本語法入門教程》、《php操作office文檔技巧總結(包括word,excel,access,ppt)》、《php日期與時間用法總結》、《php面向對象程序設計入門教程》、《php字符串(string)用法總結》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》

      希望本文所述對大家PHP程序設計有所幫助。

      www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1123792.htmlTechArticlePHP實現(xiàn)的多文件上傳類及用法示例, 本文實例講述了PHP實現(xiàn)的多文件上傳類及用法。分享給大家供大家參考,具體如下: 1、upFiles.css.php...
      本站聲明
      本文內容由網(wǎng)友自發(fā)貢獻,版權歸原作者所有,本站不承擔相應法律責任。如您發(fā)現(xiàn)有涉嫌抄襲侵權的內容,請聯(lián)系admin@php.cn

      熱AI工具

      Undress AI Tool

      Undress AI Tool

      免費脫衣服圖片

      Undresser.AI Undress

      Undresser.AI Undress

      人工智能驅動的應用程序,用于創(chuàng)建逼真的裸體照片

      AI Clothes Remover

      AI Clothes Remover

      用于從照片中去除衣服的在線人工智能工具。

      Clothoff.io

      Clothoff.io

      AI脫衣機

      Video Face Swap

      Video Face Swap

      使用我們完全免費的人工智能換臉工具輕松在任何視頻中換臉!

      熱工具

      記事本++7.3.1

      記事本++7.3.1

      好用且免費的代碼編輯器

      SublimeText3漢化版

      SublimeText3漢化版

      中文版,非常好用

      禪工作室 13.0.1

      禪工作室 13.0.1

      功能強大的PHP集成開發(fā)環(huán)境

      Dreamweaver CS6

      Dreamweaver CS6

      視覺化網(wǎng)頁開發(fā)工具

      SublimeText3 Mac版

      SublimeText3 Mac版

      神級代碼編輯軟件(SublimeText3)

      我如何了解最新的PHP開發(fā)和最佳實踐? 我如何了解最新的PHP開發(fā)和最佳實踐? Jun 23, 2025 am 12:56 AM

      TostaycurrentwithPHPdevelopmentsandbestpractices,followkeynewssourceslikePHP.netandPHPWeekly,engagewithcommunitiesonforumsandconferences,keeptoolingupdatedandgraduallyadoptnewfeatures,andreadorcontributetoopensourceprojects.First,followreliablesource

      什么是PHP,為什么它用于Web開發(fā)? 什么是PHP,為什么它用于Web開發(fā)? Jun 23, 2025 am 12:55 AM

      PHPbecamepopularforwebdevelopmentduetoitseaseoflearning,seamlessintegrationwithHTML,widespreadhostingsupport,andalargeecosystemincludingframeworkslikeLaravelandCMSplatformslikeWordPress.Itexcelsinhandlingformsubmissions,managingusersessions,interacti

      如何設置PHP時區(qū)? 如何設置PHP時區(qū)? Jun 25, 2025 am 01:00 AM

      tosetTherightTimeZoneInphp,restate_default_timezone_set()functionAtthestArtofyourscriptWithavalIdidentIdentifiersuchas'america/new_york'.1.usedate_default_default_timezone_set_set()

      我如何驗證PHP中的用戶輸入以確保其符合某些標準? 我如何驗證PHP中的用戶輸入以確保其符合某些標準? Jun 22, 2025 am 01:00 AM

      TovalidateuserinputinPHP,usebuilt-invalidationfunctionslikefilter_var()andfilter_input(),applyregularexpressionsforcustomformatssuchasusernamesorphonenumbers,checkdatatypesfornumericvalueslikeageorprice,setlengthlimitsandtrimwhitespacetopreventlayout

      什么是php(serialize(),Unserialize())中的數(shù)據(jù)序列化? 什么是php(serialize(),Unserialize())中的數(shù)據(jù)序列化? Jun 22, 2025 am 01:03 AM

      thephpfunctionserize()andunSerialize()redustoconvertComplexdatStructDestoresToroStoroStoroSandaBackagagain.1.Serialize()

      如何將PHP代碼嵌入HTML文件中? 如何將PHP代碼嵌入HTML文件中? Jun 22, 2025 am 01:00 AM

      可以將PHP代碼嵌入HTML文件中,但需確保文件以.php為擴展名,以便服務器能正確解析。使用標準的標簽包裹PHP代碼,可在HTML中任意位置插入動態(tài)內容。此外,可在同一文件中多次切換PHP與HTML,實現(xiàn)條件渲染等動態(tài)功能。務必注意服務器配置及語法正確性,避免因短標簽、引號錯誤或遺漏結束標簽導致問題。

      編寫清潔和可維護的PHP代碼的最佳實踐是什么? 編寫清潔和可維護的PHP代碼的最佳實踐是什么? Jun 24, 2025 am 12:53 AM

      寫干凈、易維護的PHP代碼關鍵在于清晰命名、遵循標準、合理結構、善用注釋和可測試性。1.使用明確的變量、函數(shù)和類名,如$userData和calculateTotalPrice();2.遵循PSR-12標準統(tǒng)一代碼風格;3.按職責拆分代碼結構,使用MVC或Laravel式目錄組織;4.避免面條式代碼,將邏輯拆分為單一職責的小函數(shù);5.在關鍵處添加注釋并撰寫接口文檔,明確參數(shù)、返回值和異常;6.提高可測試性,采用依賴注入、減少全局狀態(tài)和靜態(tài)方法。這些做法提升代碼質量、協(xié)作效率和后期維護便利性。

      如何使用PHP執(zhí)行SQL查詢? 如何使用PHP執(zhí)行SQL查詢? Jun 24, 2025 am 12:54 AM

      Yes,youcanrunSQLqueriesusingPHP,andtheprocessinvolveschoosingadatabaseextension,connectingtothedatabase,executingqueriessafely,andclosingconnectionswhendone.Todothis,firstchoosebetweenMySQLiorPDO,withPDObeingmoreflexibleduetosupportingmultipledatabas

      See all articles