zoukankan      html  css  js  c++  java
  • tp框架文件上传

    tp框架的文件上传功能也非常简便,我们一起来看一下:

    1、首先我们要在Controller文件夹下新建一个控制器TestController.class.php:

    <?php
    namespace HomeController;
    use ThinkController;
    class TestController extends Controller{
        public function shangchuan (){
            $this->show();
        }
        public function wjsc(){
            $u = newThinkUpload();
            $u->maxSize = 1024000;//设置文件大小
            $u->rootPath = "./Public/";//文件存放的根路径
            $u->savePath = "./upload/";//设置当前上传文件存放位置
            $u->exts = array('jpg','gif','png','jpeg');
            $info = $u->upload();//上传文件并返回文件信息
            if($info){
                echo "上传成功,文件存放在:".$info["file"]['savepath'];
            }
            else{
                echo $u->getError();
            }
        }
    }

    2、在View文件夹下新建一个Test文件夹,再在里边新建一个shangchuan.html页面:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    
    <body>
    <h1>文件上传</h1>
    <form action="__CONTROLLER__/wjsc" method="post" enctype="multipart/form-data">
        <input type="file" name="file" />
        <input type="submit" value="上传" />
    </form>
    </body>
    </html>

    效果图:

  • 相关阅读:
    最小生成树模板(Prim+Kruskal)
    最短路模板(Dij+Floyd)
    LeetCode双周赛#33 题解
    CSS3 学习笔记(中)
    拓扑排序小测试
    串和矩阵压缩的小测试
    树的相关小测试 题解
    Leetcode 周赛#202 题解
    HTML5 学习笔记
    Leetcode 双周赛#32 题解
  • 原文地址:https://www.cnblogs.com/mengshenshenchu/p/7145927.html
Copyright © 2011-2022 走看看