zoukankan      html  css  js  c++  java
  • Thinkphp文件上传

    1.在IndexController.class.php里面写2个方法,shangchuan用来显示页面,upload是上传文件的方法。

    <?php
    namespace HomeController;
    use ThinkController;
    class IndexController extends Controller {
        public function shangchuan()
        {
            $this->display();
        }
        public function upload()
        {
            $upload = new ThinkUpload();// 实例化上传类
            $upload->maxSize   =     31457280 ;// 设置附件上传大小
            $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->autoSub  = true;
            $upload->subName  = array('date','Ymd');
            $upload->rootPath = "./Public/";//文件上传保存的根路径,下面的Upload文件夹放在这里面,./Public/Upload
            $upload->savePath  =      './Uploads/'; // 设置附件上传目录,文件上传上来以后放在了这个文件件里面。
            $info   =   $upload->upload();
            if(!$info) // 上传错误提示错误信息
            {
                $this->error($upload->getError());
            }
            else// 上传成功 获取上传文件信息
            {
                foreach($info as $file){        
                echo $file['savepath'].$file['savename'];    
                }
            }
        }
    }
    ?>

    2.显示页面

    <!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>
    <form action="__CONTROLLER__/upload" method="post" enctype="multipart/form-data">
        <input type="file" name="wenjian" />
        <input type="submit" value="提交" />
    
    </form>
    </body>
    </html>
  • 相关阅读:
    2019hdu多校1
    codefroce842C
    [codeforce686D]树的重心
    [codeforce1188C&D]
    Educational Codeforces Round 66
    [hdu4343]interval query
    Luogu 4234 最小差值生成树
    BZOJ 2594 水管局长
    Luogu 2173 [ZJOI2012]网络
    Luogu 2147 洞穴勘测
  • 原文地址:https://www.cnblogs.com/xiaofox0018/p/6244737.html
Copyright © 2011-2022 走看看