Create sub-folders based on form field when uploading a file

alisamii

Member
Hi

Can support be added to the file upload element to enable it to automatically create a subfolder under the parent folder based on the value chosen in a select field or a specified field in my form.

I have a requirement to save files into a separate folder for each person registering on my form, but it needs to be stored in a folder named after their organisation.

Is this something that could be added easily to the existing element or something I could do myself using the php and javascript plugins?

Thanks

Ali
 
You can use placeholders to set the folder path
e.g. {$my->id}
{table___element} is working, too if it's a non-ajax fileupload (I didn't test ajax fileupload)
 
Hi:

For the above, we need to have it work as follows:
User selects an organisation from a dropdown element.
As part of the form submission, they can also upload a file (optional)

We need to save the file to a location on the server that is in the format:

/path/to/files/[organisation]/

Where [organisation] is the value of the organisation in the dropdown and is the file they have uploaded.

The system needs to be able to create the subdirectory called [organisation] if it does not exist or use the existing d
 
- Creating folders is done automatically.
- To increment filenames if the file already exists set
if existing image found? = leave existing & increment...

Upload Directory: /path/to/files/{table___your-organisation-element}
This is inserting the value/key (same as {table___your-organisation-element_raw}), so make sure the value contains the organisation's name, but in a "folder compatible" form (no spaces, no special characters etc)
 
  • Like
Reactions: rob
Hello. I just follow this instructions and work perfect if ajax fileupload it's off.
Question.
If ajax it's off how i can show on the list the diferent files that was uploaded on that folder?
Thanks For any help
 
If you are trying to do what I think you are trying to do, then you can't. Like any other element, a "normal" (non-AJAX) file upload just has one value per row. So for any given row in the 'organization' list, you can have exactly one uploaded image. If you edit a row, and upload a different file, you are simply overwriting which image that row has for that upload element.

In AJAX mode, the upload element is automatically turned in to a one-to-many join, where we create a separate table (called something like yourtable_repeat_yourelementname or some such), which then has a parent_id FK pointing back to the PK of the main row, and we store the upload element data in that repeat table. We can then render all the images (or whatever) for a given row in list / form / detail view.

However, because the AJAX uploading happens "out of band", separate to the form submission, when the file(s) are uploaded, we don't have the element data on the server side needed to do {table___elementname} placeholder substitution in the path. We would need to rewrite the upload code such that the initial AJAX upload just goes in to a temporary folder, and we then move the file(s) in to the final destination when the form is submitted. Which is how we should have done it in the first place, but didn't. So ... It is What It Is, until we have the time / funding to change it.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Staff online

Members online

Back
Top