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

example_ThinkPHP文件上传

时间:2016-05-24 00:22:40      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:

Upload控制器下的文件上传操作

技术分享
<?php
namespace Home\Controller;
use Think\Controller;
class UploadController extends Controller{
    

    public function upload(){    
    
        if(empty($_FILES))
    {
        $this->display();
    }
        else
    {
            $config = array(    
            ‘maxSize‘    =>    3145728,   
            ‘rootPath‘     =>       ‘./Public/‘,
            ‘savePath‘   =>    ‘./Uploads/‘,   
            
            ‘saveName‘   =>    ‘time‘,                   //保存文件名的值可以是字符串,数组和函数名
            ‘exts‘       =>    array(‘jpg‘, ‘gif‘, ‘png‘, ‘jpeg‘),  
            ‘autoSub‘    =>    true,   
            ‘subName‘    =>    array(‘date‘,‘Ymd‘)
        );
            
        $upload = new \Think\Upload($config);            // 实例化上传类    
        
            //上传文件    
            $info   =   $upload->upload();    
            if(!$info)
        {                                                           
            $this->error($upload->getError());            // 上传错误提示错误信息 
        }
            else
        {                                                   
                $this->success(‘上传成功!‘);              // 上传成功 
            
                foreach($info as $file)
             {        
                echo $file[‘savepath‘].$file[‘saveName‘];
             } 
        }
    }
    
}
?>
View Code

upload.html模板

技术分享
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <form action="__SELF__" enctype="multipart/form-data" method="post" >
    <input type="text" name="name" />
    <input type="file" name="photo" />
    <input type="submit" value="提交" ></form>
</body>
</html>
View Code

 

example_ThinkPHP文件上传

标签:

原文地址:http://www.cnblogs.com/sihuiming/p/5522002.html

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