Upload field. How to store the full path in database?

Is there any way to store the full path while using setFieldUpload()? The documentation says it only stores the name of the file:

The method is taking 3 parameters:

  1. The first parameter is the field name in the database. Have in mind that only the name of the file (without the full path) is stored

I need to prefix the relative path to the random generated file name. Any ideais?

TIA,
Bernhard Enders.

Is there any callback I can use to append $uploadPath or $publicPath to the auto generated filename? If I didn’t store $uploadPath or $publicPath how can I retrieve the uploaded image outside GCE pages?

Hello @bgeneto ,

Unfortunately there is not any out of the box way to do that in Grocery CRUD since the filename prefix is hardcoded currently with the below code:

if (file_exists($this->_uploadPath . '/' . $newFileName . '.' . $fileExtension)) {
    $newFileName = $newFileName . '-' .substr(uniqid(), -5);
}

I am working currently in having the callbackBeforeUpload, callbackUpload and callbackAfterUpload and I am going to release that very soon (e.g. this week). Maybe what are you looking for is a callbackUpload or a callbackAfterUpload so you can change the filename? I will inform you once the functions are available to see if this fits your needs. Also what about using the callbackAfterUpdate instead?

For example having something like this:

$crud->callbackAfterUpdate(function ($stateParameters) use ($callbackAfterUpdateModel) {

    $prefix = 'test-';

    if (!empty($stateParameters->data['photo_url']) && !strstr($stateParameters->data['photo_url'], $prefix)) {
        $photoUrlWithPrefix = $prefix .$stateParameters->data['photo_url'];

        // Create your own model and update the photo url
        $callbackAfterUpdateModel->updatePhotoUrl($stateParameters->primaryKeyValue, $photoUrlWithPrefix);
    }

    return $stateParameters;
});

What do you think? I hope this helped

Regards
Johnny