ThinkPhp架構:檔案上傳

來源:互聯網
上載者:User

標籤:his   dtd   php架構   ceshi   遍曆   設定   路徑   width   meta   

以前也做過檔案上傳,但是用TP架構做檔案上傳的原理和以前是差不多的

下面看具體的做法:

第一步:做一個Wenjian控制器:

<?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

<!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><block name="title">無標題文檔</block></title></head><body><h1>檔案上傳</h1><form action="__CONTROLLER__/wjsc" enctype="multipart/form-data" method="post" ><input type="file" name="file" /><input type="submit" value="上傳" ></form></body></html>

看一下效果:

點擊選中的檔案,並開啟

 

 檔案已經選中:

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

 

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

 

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

 

 

 

 

  

  

ThinkPhp架構:檔案上傳

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.