php 文件上傳
效果圖:
實現(xiàn)代碼:
application\index\controller\Index.php
<?php namespace app\index\controller; use think\Controller; use think\Request; class Index extends Controller { //文件上傳表單 public function index() { return $this->fetch(); } //文件上傳提交 public function upload() { //獲取表單上傳文件 $file = request()->file('files'); if (emptyempty($file)) { $this->error('請選擇上傳文件'); } //移動到框架應(yīng)用根目錄/public/uploads/ 目錄下 $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads'); if ($info) { $this->success('文件上傳成功'); echo $info->getFilename(); } else { //上傳失敗獲取錯誤信息 $this->error($file->getError()); } } }
application\index\view\index\index.html
<!doctype html> <html> <head> <meta charset="UTF-8"> <title>文件上傳</title> </head> <body> <h2>文件上傳</h2> <FORM method="post" enctype="multipart/form-data" class="form" action="{:url('upload')}">選擇文件: <INPUT type="file" class="files" name="files"><br/> <INPUT type="submit" class="btn" value=" 提交 "> </FORM> </body> </html>
以上就是php上傳文件的實例,如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
【網(wǎng)站聲明】本站除付費源碼經(jīng)過測試外,其他素材未做測試,不保證完整性,網(wǎng)站上部分源碼僅限學(xué)習交流,請勿用于商業(yè)用途。如損害你的權(quán)益請聯(lián)系客服QQ:2655101040 給予處理,謝謝支持。