溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

PHP中TP5上傳文件的示例分析

發(fā)布時間:2021-07-15 10:41:02 來源:億速云 閱讀:91 作者:小新 欄目:開發(fā)技術(shù)

小編給大家分享一下PHP中TP5上傳文件的示例分析,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!

php 文件上傳

效果圖:

PHP中TP5上傳文件的示例分析

實(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è)資訊頻道,感謝各位的閱讀!

向AI問一下細(xì)節(jié)

免責(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)容。

AI