dynamic folder in upload file

Wish to see a specific feature/change in future releases? Feel free to post it here, and if it gets enough "likes", we'd definitely include it in future releases!
Post Reply
User avatar
landinialejandro
AppGini Super Hero
AppGini Super Hero
Posts: 126
Joined: 2016-03-06 00:59
Location: Argentina
Contact:

dynamic folder in upload file

Post by landinialejandro » 2022-03-17 16:44

Hello there.
I found myself needing to be able to dynamically change the location where each file will be uploaded in a form, for example images/tablename/id.
This is possible if you could modify the 'dir' variable of the fileUpload function.
But it is not possible for me unless it is written within the base code of the application, which would be modified each time it is compiled.
I also did not find a way to pass it by parameter from the hooks functions.

On the other hand, I also found that the folder was not generated for me, and I found that the mkdir function of the PrepareUploadedFile function was missing the recursion true.

I think that it is not very far from being able to solve the first point, to be able to pass the folder by parameter.
But the second point I think can be solved with the next version

Greetings Alejandro.
Alejandro.
AppGini 5.98 - Linux OpenSuse Tumblewweed.

Some of my posts that may interest you:
:arrow: Landini Admin Template: Template for Appgini like AdminLTE
:arrow: Profile image plugin: add and changue image user profile
:arrow: Field editor in table view: Configurable fast edit fields in TV
:idea: my personal page

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1637
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: dynamic folder in upload file

Post by jsetzer » 2022-03-17 17:02

Why not use before* hooks, create subfolder depending on PK and change filename in DB?
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

User avatar
landinialejandro
AppGini Super Hero
AppGini Super Hero
Posts: 126
Joined: 2016-03-06 00:59
Location: Argentina
Contact:

Re: dynamic folder in upload file

Post by landinialejandro » 2022-03-17 17:21

Hi Jan, I'm going to try that, but it seems a bit far-fetched to me, maybe it's better in the after hook, so appgini finishes all its upload process, and I move the file to the folder I need. maybe... hahaha.
Although I still think that the suggestion could work better.
Thanks for your support.

Saludos Alejandro
Alejandro.
AppGini 5.98 - Linux OpenSuse Tumblewweed.

Some of my posts that may interest you:
:arrow: Landini Admin Template: Template for Appgini like AdminLTE
:arrow: Profile image plugin: add and changue image user profile
:arrow: Field editor in table view: Configurable fast edit fields in TV
:idea: my personal page

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1637
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: dynamic folder in upload file

Post by jsetzer » 2022-03-17 17:59

Both should be possible. If you intercept before* you will have access to $_FILES array, additionally. For example I am using before_insert hook for fetching the file's original filename and storing it in DB. Having the (unchanged) filename in DB next to the generated unique filename helps my users finding attachments using built-in search function. So, before* can bring some benefit. But you are right: both should work.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

Post Reply