How to upload files?

Hi, I am taking my first steps with GroceryCrud.
I have seen that the ‘set_field_upload’ function has been removed so what would be the best alternative to upload a file and still use GroceryCrud?
Thanks for your help!

By using Grocery Crud Enterprise :wink:

Hi @ariel ,
I am facing the same issue… Once I get a workaround I will post it for you :slight_smile:

I believe it can be done easily … especially if you used grocerygrud 1.x

Well, didn’t take me much time before achieving that…
I have written a working code. Of course it needs sanitizing … but it works

$crud = new GroceryCrud ();
$crud->setTable ('orders');
$crud->setSubject ('order', 'Orders');

// Oerride the default upload field ...
$crud->callbackAddField (
  'order_docs',
  function () {
    return '<input id="field-order_docs" type="file" class="form-control" name="order_docs" value="">';
  }
);

// Upload the file beforeInsert ...
$crud->callbackBeforeInsert (
  function ($cbData) {
    $toUpload = $this->request->getFile('order_docs');
    $toUpload->move(WRITEPATH . 'uploads');
    $cbData->data['order_docs'] = $toUpload->getName();
    return $cbData;
  }
);
// Render ...
$output = $crud->render ();

// Your uploaded files will be in CodeIgniter Directory '/writable/uploads'

It works perfectly to add a new one, but when editing the field it is text type. Any idea how to solve the problem? Many thanks