【问题标题】:codeigniter, custom error message for server max_image_sizecodeigniter,服务器 max_image_size 的自定义错误消息
【发布时间】:2018-01-26 21:18:40
【问题描述】:

我使用的是Codeigniter,上传过大图片时出现问题,即图片大小大于服务器中的upload_max_filesize。

我想为用户显示一条自定义消息而不是这条消息:

警告:36276449 字节的 POST 内容长度超过第 0 行未知中 8388608 字节的限制
您请求的操作不被允许。

【问题讨论】:

  • 使用 try catch 块。
  • 为什么? PHP 没有在这里抛出异常
  • 我使用 AJAX 和 bluemp/dropzone 文件上传器,并在允许上传特定大小的文件之前 ping 服务器询问 upload_max_filesize 和 post_max_size 是多少。

标签: php forms codeigniter validation upload


【解决方案1】:

在上传图片到服务器时,您必须进行验证,如果图片大小低于一些 MB,则允许上传到服务器上,否则会引发验证错误。

您可以使用 jQuery 验证插件来执行此操作,这是您可以使用的参考。 Validate file extension and size before submitting form

【讨论】:

    【解决方案2】:

    也许(如果您是服务器管理员)您可以增加最大帖子大小 (Increasing the maximum post size),然后通过 codeigniter 检查大小并显示消息:

    $config['max_size']             = 100;
    ...
    $this->load->library('upload', $config);
    
    if (!$this->upload->do_upload('userfile'))
    {
        //handle the error with $this->upload->display_errors()
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-14
      • 1970-01-01
      • 2011-10-30
      • 1970-01-01
      • 2011-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多