码迷,mamicode.com
首页 > Web开发 > 详细

tp 框架 -文件上传

时间:2017-07-10 23:31:51      阅读:329      评论:0      收藏:0      [点我收藏+]

标签:.com   jpg   cin   pac   选中   lsp   目录   har   图片   

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
namespace Ceshi\Controller;
use Think\Controller;
class WenjianController extends  Controller
{  
    public function shangchuan(){
        $this->show();
    }  
    public function wjsc(){
          $upload = new \Think\Upload();   // 实例化上传类   造对象
          $upload->maxSize =  1024000;     // 设置附件上传大小
          $upload->rootPath = "./Public/"; //文件存放的根路径
          $upload->savePath = "upload/";   //设置当前文件存放的位置
          $upload->exts =  array(‘jpg‘, ‘gif‘, ‘png‘, ‘jpeg‘);  // 设置附件上传类型
          $info = $upload->upload();  //上传文件并返回文件信息       
             if(!$info)
              {
                // 上传错误提示错误信息      
 
                 echo $upload->getError();
                     
             }else{
                 //上传成功,遍历$info,
                 //因为返回成功上传的文件信息数组是二维数组
                  foreach($info as $file)
                  {      
                     echo "上传成功,文件存放在:".$file[‘savepath‘].$file[‘savename‘];   
                  }
             }
    }
     
         
         
}

  第二步:做显示页面 shangchuan.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <h1>文件上传</h1>
        <!--要使用上传功能 你的表单需要设置 enctype="multipart/form-data"-->
        <form action="__CONTROLLER__/wjsc" method="post" enctype="multipart/form-data">
            <input type="file"  name="file"/>
            <input type="submit" value="上传" />           
        </form>
    </body>
</html>

  看一下效果:

技术分享

点击选中的文件,并打开

技术分享

 

文件已经选中:

 

技术分享

点击上传:会显示上传成功,并输出   路径  加  文件名

技术分享

 

 看一下Public文件下的upload文件是否已上传该文件:

 

 技术分享

 

 选中的图片已经上传到该目录下了~~~~~

 

tp 框架 -文件上传

标签:.com   jpg   cin   pac   选中   lsp   目录   har   图片   

原文地址:http://www.cnblogs.com/Liangbingbing/p/7147836.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!