【问题标题】:Grocery Crud - Set the allowed file types in upload fieldGrocery Crud - 在上传字段中设置允许的文件类型
【发布时间】:2014-01-06 06:38:48
【问题描述】:

我的问题和这个http://www.grocerycrud.com/forums/topic/169-allowed-types-for-file-upload/类似

那里的答案不再更新。

如何在 1.4 版的杂货店中设置允许的文件上传类型? 文件类型可以直接从函数中设置吗?像这样的:

$crud->set_upload_file_types('jpg','apk');

谢谢

【问题讨论】:

  • 请在此处发布您的问题。不要仅仅将我们链接到外部网站。

标签: php codeigniter grocery-crud


【解决方案1】:

此时您不能直接从控制器功能更改它。 但是你可以从你的 application/config/grocery_crud.php 的配置文件中改变它

$config['grocery_crud_file_upload_allow_file_types'] = 'gif|jpeg|jpg|png|tiff|doc|docx|txt|odt|xls|xlsx|pdf|ppt|pptx|pps|ppsx|mp3|m4a|ogg|wav|mp4|m4v|mov|wmv|flv|avi|mpg|ogv|3gp|3g2|apk';

【讨论】:

    【解决方案2】:

    我有同样的问题(我可以轻松地按照 Jawaad 所说的去做,但我需要为每个字段定义文件类型)。这是我的解决方案:

    https://github.com/scoumbourdis/grocery-crud/pull/290/files

    向 GroceryCrud 发送拉取请求,他们是否选择使用它取决于他们。

    有关说明,请参阅提交消息 (https://github.com/scoumbourdis/grocery-crud/pull/290)

    【讨论】:

    • 嗨,Syrys,欢迎来到 Stack Overflow。这里的政策是避免仅链接的答案。换句话说,您应该编辑您的答案以 include 您的解决方案,而不是链接到某人可以找到它的地方。这有助于使网站具有可读性、可搜索性和可持续性。
    【解决方案3】:

    我尝试了另一种解决方案,它正在工作

    $crud->set_field_upload("image","assets/uploads/team","jpg|png");

    它只是添加允许的文件类型,如我的代码中用'|'分隔

    【讨论】:

      【解决方案4】:

      在 Grocery Crud 和 Codeigniter 版本 3 中 100% 工作 你会配置你的

      在文件夹中 application/config/grocery_crud.php

      $config['grocery_crud_file_upload_allow_file_types'] = 'gif|jpeg|jpg|png|tiff|doc|docx|txt|odt|xls|xlsx|pdf|ppt|pptx|pps|ppsx|mp3|m4a|ogg|wav|mp4|m4v|mov|wmv|flv|avi|mpg|ogv|3gp|3g2|apk';
      

      With $crud->set_field_upload("image","assets/uploads/team","jpg|png");您根本无法覆盖,它从上面的grocery_crud.php 中选择扩展名。

      最后在你的控制器中,这是我的例子:

       function __construct() {
              parent::__construct();
              $this->load->driver('session');
              $this->load->database();
              $this->load->helper('url');
              $this->load->library('grocery_CRUD');
              $this->load->model('Generic');
              $this->load->library('upload');
              $this->load->helper(array('form','url'));
      
           //$config['upload_path']          = './uploads/';
          $config['allowed_types']        = 'gif|jpg|png|rar|zip';
          $config['max_size']             = 100;
          $config['max_width']            = 1024;
          $config['max_height']           = 768; 
          $this->load->library('upload', $config);
          $this->upload->initialize($config);
      }
      
      
      
          public function index() {
          $crud = new grocery_CRUD();
          ...
            //dondt forget to set some configuration of visibily from your crud pages where you   want your Upload Input appears like...
          $crud->fields("file_url" ...
          $crud->add_fields("file_url"..
          $crud->edit_fields("file_url"..
         ....
           $crud->set_field_upload('file_url','assets/uploads/files');
           $output = $crud->render();
          ....
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-12-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多