thinkPHP3.2簡單實現檔案上傳的方法,_PHP教程

來源:互聯網
上載者:User

thinkPHP3.2簡單實現檔案上傳的方法,


本文執行個體講述了thinkPHP3.2簡單實現檔案上傳的方法。分享給大家供大家參考,具體如下:

IndexController.class.php:

<?phpnamespace Home\Controller;use Think\Controller;class IndexController extends Controller { function index(){   $this->display(); } public function upload(){  $upload = new \Think\Upload();// 執行個體化上傳類  $upload->maxSize = 3145728 ;// 設定附件上傳大小  $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 設定附件上傳類型  $upload->rootPath = './Uploads/'; // 設定附件上傳根目錄  $upload->savePath = ''; // 設定附件上傳(子)目錄  // 上傳檔案  $info = $upload->upload();  print_r($info);exit;  if(!$info) {// 上傳錯誤提示錯誤資訊  $this->error($upload->getError());  }else{// 上傳成功  $this->success('上傳成功!');  }  }}?>

index.html:

在view裡建個和控制器同名的檔案夾 Index 再建個和方法同名的html index檔案,這裡省略。

補充:小編在這裡推薦一款本站的php格式化美化的排版工具協助大家在以後的PHP程式設計中進行代碼排版:

php代碼線上格式化美化工具:http://tools.jb51.net/code/phpformat

更多關於thinkPHP相關內容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《ThinkPHP常用方法總結》、《smarty模板入門基礎教程》及《PHP模板技術總結》。

希望本文所述對大家基於ThinkPHP架構的PHP程式設計有所協助。

http://www.bkjia.com/PHPjc/1127887.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1127887.htmlTechArticlethinkPHP3.2簡單實現檔案上傳的方法, 本文執行個體講述了thinkPHP3.2簡單實現檔案上傳的方法。分享給大家供大家參考,具體如下: IndexController...

  • 聯繫我們

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