您好,登錄后才能下訂單哦!
小編給大家分享一下PHP中TP5上傳文件的示例分析,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
php 文件上傳
效果圖:
實(shí)現(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> <h3>文件上傳</h3> <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中TP5上傳文件的示例分析”有了一定的了解,如果想了解更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。