【问题标题】:Set Max Size in CodeIgniter File Upload在 CodeIgniter 文件上传中设置最大大小
【发布时间】:2019-12-05 22:46:10
【问题描述】:

我已经使用这个私有函数在 CodeIgniter 项目中上传文件。我从来没有在这个函数中设置过 max_size。这里,如何在这个私有函数中设置max_size?

private function do_upload($value){
    $type = explode('.', $_FILES[$value]["name"]);
    $type = $type[count($type)-1];
    $url = "./assets/uploads/products/".uniqid(rand()).'.'.$type;

    if(in_array($type, array("jpg","jpeg","gif","png")))

    if(is_uploaded_file($_FILES[$value]["tmp_name"]))

    if(move_uploaded_file($_FILES[$value]["tmp_name"], $url))

    return $url;

    return "";
}

【问题讨论】:

标签: php codeigniter file-upload


【解决方案1】:

推荐:https://codeigniter.com/userguide3/libraries/file_uploading.html 2MB(或 2048 KB)这样:

$config['max_size'] = 1024 * 10; // <= 10Mb;

【讨论】:

    【解决方案2】:

    您可以在您的网站基础文件夹中创建一个 php.ini 文件

    并添加以下内容(2M = 2 兆字节,您可以添加所需的大小)

    upload_max_filesize = 2M;
    

    在上面

    【讨论】:

      【解决方案3】:

      只需这样做。

      if($_FILES["my_file_name"]['size'] > 1900000){  //set my_file_name to yours <input type="file" name="my_file_name">
      
        echo "file is too large";
      
      }else{
      
        echo "file meets the minimum size";   
      
      }
      

      如果您想为您的系统设置更大的上传大小,您需要转到 php.ini 文件并进行更改。

      upload_max_filesize = 2M; //change this to your desired size.
      

      希望有帮助。

      【讨论】:

        【解决方案4】:

        您可以通过 $_FILES['uploaded_file']['size'] 获取该文件的大小, 例如:

        $maxsize=2097152;
        if(($_FILES['uploaded_file']['size'] >= $maxsize)) {
                $errors[] = 'File too large. File must be less than 2 megabytes.';
            }
        

        【讨论】:

          猜你喜欢
          • 2019-04-22
          • 1970-01-01
          • 2016-09-29
          • 2019-12-16
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-01-17
          • 2018-06-07
          相关资源
          最近更新 更多