dynamic folder in upload file
- landinialejandro
- AppGini Super Hero
- Posts: 126
- Joined: 2016-03-06 00:59
- Location: Argentina
- Contact:
dynamic folder in upload file
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.
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:
Landini Admin Template: Template for Appgini like AdminLTE
Profile image plugin: add and changue image user profile
Field editor in table view: Configurable fast edit fields in TV
my personal page
AppGini 5.98 - Linux OpenSuse Tumblewweed.
Some of my posts that may interest you:
Landini Admin Template: Template for Appgini like AdminLTE
Profile image plugin: add and changue image user profile
Field editor in table view: Configurable fast edit fields in TV
my personal page
Re: dynamic folder in upload file
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
AppGini 24.14 Revision 1665 + all AppGini Helper tools
<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 readabilityAppGini 24.14 Revision 1665 + all AppGini Helper tools
- landinialejandro
- AppGini Super Hero
- Posts: 126
- Joined: 2016-03-06 00:59
- Location: Argentina
- Contact:
Re: dynamic folder in upload file
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
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:
Landini Admin Template: Template for Appgini like AdminLTE
Profile image plugin: add and changue image user profile
Field editor in table view: Configurable fast edit fields in TV
my personal page
AppGini 5.98 - Linux OpenSuse Tumblewweed.
Some of my posts that may interest you:
Landini Admin Template: Template for Appgini like AdminLTE
Profile image plugin: add and changue image user profile
Field editor in table view: Configurable fast edit fields in TV
my personal page
Re: dynamic folder in upload file
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
AppGini 24.14 Revision 1665 + all AppGini Helper tools
<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 readabilityAppGini 24.14 Revision 1665 + all AppGini Helper tools
Re: dynamic folder in upload file
Hi,
I am not sure, if the problem was solved - however, I do have the same need now:
In the generic upload folder are currently almost 20.000 files: documents and images.
I would like to split this into subfolders. e.g. if the regular upload folder is /images, if the uploaded file has the primary key "3" (all PKs are autonumber), the uploaded file should reside in /images/003. If the pk is 456124 the file would be in /images/124:
Take a right-padded PK and create a subfolder. Of course, this means upload with PK 14003 would also reside in /images/003 - that's fine.
After some experiments, I notice, that I COULD add the folder to the fieldname. Example: Fieldname that holds the name to the uploaded file as it it saved is "myDocument".
would become (simply using after_insert/after_update hooks)
notice the new prefix 004/ of the filename.
This seems to work for documents (files that are NOT images)
For images let's make another example:
would become
It seems to work for images - BUT not for the thumbnails. Even when the thumbnails 017/AB2134F91_tv.jpg and 017/AB2134F91_dv.jpg exist (in the subdirectory) - the thumbnails are not displayed, just the general placeholder is shown.
I created a sample application and allowed to zoom the image (setting in AG). Thus clicking on the (mistakenly displayed) placeholder zooms the CORRECT image.
Side-Question:
I have not yet looked into when the thumbnails are being generated: Is that before or after the "after_..." - hook?
Thus my question:
How can a simple code be added that is universally working for all uploads (also images with their thumbnails)?
Of course it's preferred, that this is code (a file) that not once files that are being regenerated.
Thanks a lot for any help
Olaf
I am not sure, if the problem was solved - however, I do have the same need now:
In the generic upload folder are currently almost 20.000 files: documents and images.
I would like to split this into subfolders. e.g. if the regular upload folder is /images, if the uploaded file has the primary key "3" (all PKs are autonumber), the uploaded file should reside in /images/003. If the pk is 456124 the file would be in /images/124:
Take a right-padded PK and create a subfolder. Of course, this means upload with PK 14003 would also reside in /images/003 - that's fine.
After some experiments, I notice, that I COULD add the folder to the fieldname. Example: Fieldname that holds the name to the uploaded file as it it saved is "myDocument".
Code: Select all
pk I myDocument
---------------------
4 I 09712CAEF31.pdf
Code: Select all
pk I myDocument
---------------------
4 I 004/09712CAEF31.pdf
This seems to work for documents (files that are NOT images)
For images let's make another example:
Code: Select all
pk I myImage
---------------------
17 I AB2134F91.jpg
Code: Select all
pk I myImage
---------------------
17 I 017/AB2134F91.jpg
I created a sample application and allowed to zoom the image (setting in AG). Thus clicking on the (mistakenly displayed) placeholder zooms the CORRECT image.
Side-Question:
I have not yet looked into when the thumbnails are being generated: Is that before or after the "after_..." - hook?
Thus my question:
How can a simple code be added that is universally working for all uploads (also images with their thumbnails)?
Of course it's preferred, that this is code (a file) that not once files that are being regenerated.
Thanks a lot for any help
Olaf
Some postings I was involved, you might find useful:
Multi Path Upload (MPU) / dynamic upload folder; SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button
Multi Path Upload (MPU) / dynamic upload folder; SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button
Re: dynamic folder in upload file
A few years ago someone from scandinavia told me about performance problems with directories having >10000 files - even in Linux.
In a different project for them I have auto created subdirectories per master record, moved uploaded files there and changed the path, stored in DB, to reflect the new storage location.
You may consider something like that.
In a different project for them I have auto created subdirectories per master record, moved uploaded files there and changed the path, stored in DB, to reflect the new storage location.
You may consider something like that.
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.14 Revision 1665 + all AppGini Helper tools
<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 readabilityAppGini 24.14 Revision 1665 + all AppGini Helper tools
Re: dynamic folder in upload file
Hi Jan,
thank you for your answer.
Indeed, the uploads folder has almost 18000 files now. It's uploaded PDFs and images (jpg), the latter of course with _dv and _tv alternatives (total filenumber is around 18000).
Your suggestion seems to me like my
where I add the id as file prefix and place the file in the subfolder /uploads/004/09712CAEF31.pdf .
For PDFs this works as described. Unfortunately image previews (_dv and _tv) do not work. Once I click on the "broken" preview icon, the image can be displayed without problems.
I suppose the problem is in /thumbnails.php:
In thumbnails the upload dir gets pulled from incfunctions.php -> getUploadDir() . This seems to return the regular upload dir with a slash in the end. So far, so good.
Currently I am trying to figure out if I "only" need to change thumnail.php ... to fix the display of the thumbs.
Once this works, "moving" files with the after_ hooks (described in my previous post) should work.
EDIT 1:
in /thumbnails.php
changing
to
will handle subfolders fine ... for displaying.
Currently no generated thumbs are removed when the main image file is deleted from the server. I need to investigate this
Olaf
thank you for your answer.
Indeed, the uploads folder has almost 18000 files now. It's uploaded PDFs and images (jpg), the latter of course with _dv and _tv alternatives (total filenumber is around 18000).
Your suggestion seems to me like my
Code: Select all
pk I myDocument
---------------------
4 I 004/09712CAEF31.pdf
For PDFs this works as described. Unfortunately image previews (_dv and _tv) do not work. Once I click on the "broken" preview icon, the image can be displayed without problems.
I suppose the problem is in /thumbnails.php:
In thumbnails the upload dir gets pulled from incfunctions.php -> getUploadDir() . This seems to return the regular upload dir with a slash in the end. So far, so good.
Currently I am trying to figure out if I "only" need to change thumnail.php ... to fix the display of the thumbs.
Once this works, "moving" files with the after_ hooks (described in my previous post) should work.
EDIT 1:
in /thumbnails.php
changing
Code: Select all
if (!preg_match('/^[a-z0-9_-]+\.(jpg|jpeg|gif|png|webp)$/i', $i, $m)) {
Code: Select all
if (!preg_match('/^[a-z0-9_-_\/]+\.(jpg|jpeg|gif|png|webp)$/i', $i, $m)) {
Currently no generated thumbs are removed when the main image file is deleted from the server. I need to investigate this
Olaf
Some postings I was involved, you might find useful:
Multi Path Upload (MPU) / dynamic upload folder; SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button
Multi Path Upload (MPU) / dynamic upload folder; SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button
Re: dynamic folder in upload file
Hi Jan and landinialejandro and all others,
please see my teaser (soon: solution) here: viewtopic.php?f=12&t=5349
Olaf
please see my teaser (soon: solution) here: viewtopic.php?f=12&t=5349
Olaf
Some postings I was involved, you might find useful:
Multi Path Upload (MPU) / dynamic upload folder; SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button
Multi Path Upload (MPU) / dynamic upload folder; SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button