setFieldBlob(string $fieldName, string $filenameField, string $temporaryUploadDirectory, string $maxUploadSize)
Enable the upload functionality for Blob field type. For example: BLOB, MEDIUMBLOB,... e.t.c.
- $fieldName: The field name that has the blob field type. For example: BLOB, MEDIUMBLOB,... e.t.c. Please also consider to have it NULL-able in case this field is not required.
- $filenameField: The field name to store the filename of the blob file. As we are using two fields and the functionality is not supporting editing functionality for the filename (for now), it is strongly suggested for you to remove the field name from editing by simply using:
- $temporaryUploadDirectory: Please use a private folder for security (e.g. to not be accessible via public link). Also make sure that you have write access to the folder. This folder is only used in order to temporary upload the file and then Grocery CRUD will delete the uploaded file automatically. This folder is a required field for security reasons as it is also required by PHP.
- $maxUploadSize: One letter maximum file size. For example: '1M' equals with 1MB, '256K' equals '256KB',.... e.t.c. This is a required field as we are not always certain about the specific maximum upload size that we would like our system to support. If you would like to use the standard fixed maximum size per field type you can use
GroceryCrud\Core\Helpers\BlobFieldTypeHelper. For more you can also check the full example below
$crud->setFieldBlob('my_blob', 'blob_filename', 'application/private/tmp', '2M');
use GroceryCrud\Core\Helpers\BlobFieldTypeHelper; ... $crud->setTable('customers'); $crud->setSubject('Customer', 'Customers'); $crud->columns(['customerName','phone','addressLine1','creditLimit', 'image']); // You will need to make sure that you unset the image_filename field as this is not an editable field $crud->unsetFields(['image_filename']); $crud->unsetColumns(['image_filename']); $crud->setFieldBlob('image', 'image_filename', 'application/private/tmp', BlobFieldTypeHelper::getFilesizeFromFieldType('MEDIUMBLOB')); $output = $crud->render();