首页 > Web开发 > 详细

tp框架文件上传

时间:2017-07-10 15:40:53      阅读:251      评论:0      收藏:0      [点我收藏+]

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

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

<?php
namespace Home\Controller;
use Think\Controller;
class TestController extends Controller{
    public function shangchuan (){
        $this->show();
    }
    public function wjsc(){
        $u = new\Think\Upload();
        $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>

效果图:

技术分享

技术分享

技术分享

 

tp框架文件上传

原文:http://www.cnblogs.com/mengshenshenchu/p/7145927.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!