thinkphp檔案上傳

來源:互聯網
上載者:User

標籤:value   upload   style   xmlns   控制   script   架構   color   尾碼   

TP架構中的檔案上傳類似於php原生的檔案上傳方法,只不過TP架構將檔案上傳的方法封裝成類來使用

1.首先我們在控制器類檔案中寫出一個上傳的顯示頁面的方法

public function shangchuan(){        $this->show();    }

同時我們在相對應的視圖檔案夾view中的建立出最上層顯示頁面

<!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" /><script src="__ROOT__/Public/js/jquery-1.11.2.min.js"></script><title>檔案上傳</title></head><body><form action="__CONTROLLER__/wjsc" method="post"    //指向wjsc操作方法enctype="multipart/form-data"><input type="file" name="file" /><input type="submit" value="上傳" /></form></body></html>

wjsc 檔案上傳的操作方法

    public function wjsc(){                $u=new \Think\Upload;  //在upload檔案中建立對象        $u->maxSize= 1024000;    //設定上傳檔案的最大值        $u->rootPath= "./Public"; //檔案上傳的儲存根目錄        $u->savePath="./upload/";  //檔案上傳的儲存目錄        $u->exts=array(‘jpg‘,‘gif‘,‘png‘,‘jpeg‘); //規定檔案的尾碼        $info=$u->upload();   //檔案上傳方法,並返回上傳的資訊        if($info){echo "上傳成功,檔案存放在".$info["file"][‘savepath‘];}  //判斷,如果上傳成功        else{$u->getRrror();}             //上傳失敗顯示錯誤資訊        }

 

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.