ThinkPHP上次和下载封装

Posted 孙中明

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ThinkPHP上次和下载封装相关的知识,希望对你有一定的参考价值。

html

<a rel="nofollow" href="$v.url" onclick="count($v.id)"><img src="__PUBLIC__/FrontStyle/img/img_project/down.png" class="downimg2"></a>
<script type="text/javascript">
            function count(obj) 
                $.ajax(
                    url:":U(/Files/count)",
                    type:post,
                    dataType: json, 
                    data:"id":obj
                );
            

    </script>

php

Files/count的的函数中,后台获取到了前台的函数进行对数据库操作

public function count()
    $map["id"]=$_POST["id"];
    $res=M("Files")->where($map)->setInc(pv,1);

html

 <form action=":U(/News/save_blog)" method="post" id="myform" name="myform" enctype="multipart/form-data">
<td>
<input type="file" name="file" style="width: 80%; height: 30px" />
<i class="msg require-red"></i>
</td>
 public function save_blog()

        if (is_uploaded_file ( $_FILES [file] [tmp_name] )) 
            $icon = $_FILES [file];

            $iconPath = "Public/images/news/" . time () . $icon [name];
            $data ["file"] ="/$iconPath";

            $icon [name] = iconv(utf-8,gb2312,$icon [name]);
            $iconPath = "Public/images/news/" .time (). $icon [name];

            move_uploaded_file ( $icon [tmp_name], $iconPath );

        

$icon [name] = iconv(utf-8,gb2312,$icon [name]);
是为了解决文件上传的时候中文乱码的情况
然后然后才能给予正确的移动路径,然后再进行

$iconPath = "Public/images/news/" .time (). $icon [name];
move_uploaded_file ( $icon [tmp_name], $iconPath );

        $id=I(post.id);
        if($id>0)

            $map[id]=$id;
            $data[add_time]=time();
            $res=$this->blog_model->where($map)->save($data);
            if($res)
                $this->success("编辑成功",U(/News/index));
            else
                $this->success("编辑失败",U(/News/index));
            

        else

            $res=$this->blog_model->add($data);
            if($res)
                $this->success("添加成功",U(/News/index));
            else
                $this->success("添加失败",U(/News/index));
            
        
    

以上是关于ThinkPHP上次和下载封装的主要内容,如果未能解决你的问题,请参考以下文章

ThinkPHP帮忙砍价任务赚钱源码 可封装APP

thinkphp导出excel功能封装

ThinkPHP-5.0.23新的RCE漏洞测试和POC

thinkphp 目录结构

thinkphp5怎么获取上次登录ip

thinkphp前端和后端怎么通信