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!
post by ariel on Apr 20, 2021
post by cybernicois on Apr 23, 2021
By using Grocery Crud Enterprise ![]()
2 months later
post by panv on Jun 27, 2021
Hi @ariel ,
I am facing the same issue… Once I get a workaround I will post it for you ![]()
I believe it can be done easily … especially if you used grocerygrud 1.x
post by panv on Jun 28, 2021
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'
25 days later
post by sailer99 on Jul 23, 2021
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
3 months later
post by panv on Oct 27, 2021
Sorry for being away for this long. Of course when you edit it will be a text type… What do you want it to be? You need to override that … Have you solved your issue yet?
24 days later
post by nbaever3 on Nov 21, 2021
i try this and this is really helpful for me thank you for sharing your reply
2 months later
post by agentzsmth on Feb 3, 2022
thanks for sharing these codes,
New & Unread Topics
| Topic | Replies | Views | Activity | |
|---|---|---|---|---|
| How can I trim search fields in datagrid before the search starts? |
|
2 | 490 | May 9 |
| At least in v1.x: primary key not encoded in read / action URLs |
|
0 | 450 | May 3 |
| Grocery crud 1.6+ stable export filtered data |
|
0 | 317 | Aug 3 |
| Use callbackColumn() but keep inline edit functionality |
|
3 | 644 | Apr 12 |
| displayAs() doesn’t support new line in headings |
|
4 | 867 | Jan 5 |