PHP中TP5 上傳檔案的方法

墨辰丷
發布: 2023-03-26 17:48:02
原創
6564 人瀏覽過

這篇文章主要介紹了PHP中TP5 上傳檔案的實例詳解的相關資料,這裡實作PHP 的上傳檔案的實例,需要的朋友可以參考下

php 檔案上傳

效果圖:

實作程式碼:

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(&#39;files&#39;); 
    if (emptyempty($file)) { 
      $this->error(&#39;请选择上传文件&#39;); 
    } 
    //移动到框架应用根目录/public/uploads/ 目录下 
    $info = $file->move(ROOT_PATH . &#39;public&#39; . DS . &#39;uploads&#39;); 
    if ($info) { 
      $this->success(&#39;文件上传成功&#39;); 
      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(&#39;upload&#39;)}">选择文件: 
  <INPUT type="file" class="files" name="files"><br/> 
  <INPUT type="submit" class="btn" value=" 提交 "> 
</FORM> 
</body> 
</html>
登入後複製

##相關推薦:

php readfile()修改檔案上傳大小案例

php ajax無重新整理檔案上傳實作步驟詳解

php實作網頁檔案上傳功能詳解

以上是PHP中TP5 上傳檔案的方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!