简体   繁体   English

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

[英]Grocery Crud - Set the allowed file types in upload field

My question is similar to this one http://www.grocerycrud.com/forums/topic/169-allowed-types-for-file-upload/我的问题类似于这个http://www.grocerycrud.com/forums/topic/169-allowed-types-for-file-upload/

The answer there is no longer updated.那里的答案不再更新。

how can I set allowed types for file upload in grocery crud with the version 1.4?如何在 1.4 版的杂货杂货中设置允许的文件上传类型? Could the file types be set directly from the function?可以直接从函数中设置文件类型吗? Something like this one:像这样的东西:

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

Thanks谢谢

At this moment you can not change it directly from the controller function.此时您不能直接从控制器功能更改它。 But you can change it from the config file at your application/config/grocery_crud.php但是您可以从 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';

I had the same issue (i could easily do what Jawaad said, but i needed to define file types for each field).我遇到了同样的问题(我可以轻松地按照 Jawaad 所说的去做,但我需要为每个字段定义文件类型)。 Here is my solution:这是我的解决方案:

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

Sent a pull request to GroceryCrud, if they choose to use it or not is upto them.向 GroceryCrud 发送拉取请求,他们是否选择使用它取决于他们。

Refer to the commit msg for instructions ( https://github.com/scoumbourdis/grocery-crud/pull/290 )有关说明,请参阅提交 msg ( https://github.com/scoumbourdis/grocery-crud/pull/290 )

i tried another solution and it is working我尝试了另一种解决方案,它正在工作

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

it just to add the allowed file types like in my code separated by '|'它只是添加允许的文件类型,如在我的代码中以“|”分隔

Works 100% in Grocery Crud and Codeigniter version 3 you'd configure your在您配置的 Grocery Crud 和 Codeigniter 版本 3 中 100% 工作

in the folder application/config/grocery_crud.php在文件夹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");使用 $crud->set_field_upload("image","assets/uploads/team","jpg|png"); you cant overide at all , it picks extension from above grocery_crud.php.您根本无法覆盖,它从杂货_crud.php 上方选择扩展名。

Finally in your controller ,this is my example :最后在你的控制器中,这是我的例子:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM