《PHP編程:PHP中TP5 上傳文件的實例詳解》要點:
本文介紹了PHP編程:PHP中TP5 上傳文件的實例詳解,希望對您有用。如果有疑問,可以聯系我們。
php 文件上傳PHP實戰
效果圖:PHP實戰
PHP實戰
實現代碼:PHP實戰
application\index\controller\Index.php
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('請選擇上傳文件'); } //移動到框架應用根目錄/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
PHP實戰
<!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上傳文件的實例,如有疑問請留言或者到本站社區交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!PHP實戰
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/407.html