標籤:.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 架構 -檔案上傳