Frage

My question is similar to this one 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? Could the file types be set directly from the function? Something like this one:

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

Thanks

War es hilfreich?

Lösung

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

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

Andere Tipps

I had the same issue (i could easily do what Jawaad said, but i needed to define file types for each field). Here is my solution:

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.

Refer to the commit msg for instructions (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");

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

in the folder 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"); you cant overide at all , it picks extension from above grocery_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();
    ....
    }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top