美文网首页
CI的分页和文件上传小实例

CI的分页和文件上传小实例

作者: playman | 来源:发表于2018-06-24 21:47 被阅读0次

    CI自带的内容

    分页内容
    文件上传

    分页使用

    public function test()
    {
        $config['base_url'] = site_url('user/test');
        $config['total_rows'] = '200';
        $config['per_page'] = '20';
    
    
        // 转成整数,获取内容
        $offset = intval($this->uri->segment(3));
        // 在这里拼接sql语句,这里返回的是偏移量
        echo $offset;
    
        // 自定义内容
        $config['first_link'] = '首页';
        $config['last_link'] = '尾页';
        $config['next_link'] = '下一页';
        $config['prev_link'] = '上一页';
    
        $this->pagination->initialize($config);
    
        echo $this->pagination->create_links();
    
    }
    
    注意:__contruct方法写完之后,要添加parent::__contruct否则会找不到
    

    文件上传

    user.php

    public function upload()
    {
        echo "upload";
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
    
        $this->load->library('upload', $config);
        $bool = $this->upload->do_upload('pic');
        echo $bool;
        // $this->upload->initialize($config);
         var_dump($this->upload->data());
        $data = $this->upload->data();
        echo $data['file_name'];
    }
    

    uploadfile.php

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>上传文件</title>
        <link rel="stylesheet" href="">
    </head>
    <body>
        <form action="<?php echo site_url('user/upload') ?>" method="post" enctype="multipart/form-data">
            <input type="file" name="pic" />
            <input type="submit" value="上传" />
        </form>
    </body>
    </html>
    

    相关文章

      网友评论

          本文标题:CI的分页和文件上传小实例

          本文链接:https://www.haomeiwen.com/subject/tawsyftx.html