Codeigniter中的上传大小限制 [英] upload size limit in codeigniter

查看:88
本文介绍了Codeigniter中的上传大小限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户可以注册的页面。他在此过程中上传了个人资料照片。我想限制大小,但是除了$ config ['maxsize']之外,没有对Codeigniter文档进行过多强调。我尝试了以下操作,但没有收到任何消息。我将大小设置为10(KB)仅用于测试。我是否必须以某种方式处理它,以使消息传达到我的观点?

I have a page where user can register. He uploads a profile picture in the process. I want to limit the size but there is not much emphasis on codeigniter documentation except for $config['maxsize']. I tried the following but I don't get any messages. I set the size to 10 (KB) just for testing. Do I have to handle it somehow to get the message across to my view?

public function add_user()
    {


        $config['upload_path']   = './uploads/';        
        $config['allowed_types'] = 'gif|jpg|png|jpeg';
        $config['max_size'] = '10';
        //$config['max_width'] = '1024';
        //$config['max_height'] = '768';

        $this->load->library('upload', $config);
        $fullImagePath;
        if (isset($_FILES['userfile']) && !empty($_FILES['userfile']['name']))
          {
          if ($this->upload->do_upload('userfile'))
          {
            // set a $_POST value for 'image' that we can use later
...

通过此代码在我的模型中的方式。

By the way this code is in my Model.

推荐答案

@Chetan Wadhwa,

@Chetan Wadhwa,

您确定尺寸为以字节为单位(不以KB为单位)。请参阅codeigniter文档: http://www.codeigniter.com/user_guide/libraries/file_uploading.html ,必须以KB为单位。

Are you sure the size is in Bytes(Not in KB). Refer codeigniter documentation: http://www.codeigniter.com/user_guide/libraries/file_uploading.html, must be in KB.

这篇关于Codeigniter中的上传大小限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆