首页 文章

Grocery Crud - 在上传字段中设置允许的文件类型

提问于
浏览
1

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

答案不再更新 .

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

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

谢谢

4 回答

  • 0

    此时您无法直接从控制器功能更改它 . 但您可以从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发送了一个拉取请求,如果他们选择使用或不使用它 .

    有关说明,请参阅commit msg(https://github.com/scoumbourdis/grocery-crud/pull/290

  • 1

    我尝试了另一种解决方案,它正在运行

    $ crud-> set_field_upload( “图像”, “资产/上传/团队”, “JPG | PNG”);

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

  • 3

    在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';
    

    使用$ 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();
        ....
        }
    

相关问题