tp 架構 -檔案上傳

來源:互聯網
上載者:User

標籤:.com   jpg   cin   pac   選中   lsp   目錄   har   圖片   

12345678910111213141516171819202122232425262728293031323334 <?phpnamespace Ceshi\Controller;use Think\Controller;class WenjianController extends  Controller{       public function shangchuan(){        $this->show();    }       public function wjsc(){          $upload = new \Think\Upload();   // 執行個體化上傳類   造對象          $upload->maxSize =  1024000;     // 設定附件上傳大小          $upload->rootPath = "./Public/"; //檔案存放的根路徑          $upload->savePath = "upload/";   //設定當前檔案存放的位置          $upload->exts =  array(‘jpg‘, ‘gif‘, ‘png‘, ‘jpeg‘);  // 設定附件上傳類型          $info = $upload->upload();  //上傳檔案並返迴文件資訊                     if(!$info)              {                // 上傳錯誤提示錯誤資訊                         echo $upload->getError();                                  }else{                 //上傳成功,遍曆$info,                 //因為返回成功上傳的檔案資訊數組是二維數組                  foreach($info as $file)                  {                            echo "上傳成功,檔案存放在:".$file[‘savepath‘].$file[‘savename‘];                      }             }     }                       }

  第二步:做顯示頁面 shangchuan.html

123456789101112131415 <!DOCTYPE html><html>    <head>        <meta charset="UTF-8">        <title></title>    </head>    <body>        <h1>檔案上傳</h1>        <!--要使用上傳功能 你的表單需要設定 enctype="multipart/form-data"-->        <form action="__CONTROLLER__/wjsc" method="post" enctype="multipart/form-data">            <input type="file"  name="file"/>            <input type="submit" value="上傳" />                    </form>    </body></html>

  看一下效果:

點擊選中的檔案,並開啟

 

檔案已經選中:

 

點擊上傳:會顯示上傳成功,並輸出   路徑  加  檔案名稱

 

 看一下Public檔案下的upload檔案是否已上傳該檔案:

 

 

 

 選中的圖片已經上傳到該目錄下了~~~~~

 

tp 架構 -檔案上傳

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.