actions_config[3]["upload_path"] = "/home/sites/xxxx/images/movements".DS.$year.DS;?>In the example image above the year is 2014. So when I want to upload a file to that record, the file has to be uploaded in the 2014 folder (in images/movements). This part isn't working.After the custom code I have a file upload. In there I left the upload_path emtpy.So when I test my form, the filename is stored in the database, but the file isn't uploaded. I think I am doing something wrong with the custom code....Hope someone can help me.Regards,Ruud"> File upload: input field in dynamic Path - Forums

Forums

File upload: input field in dynamic Path

flyboeing 06 Nov, 2015
Hello all,

For my CC list I created a ChronoForm to edit a record. For this I used this tutorial:


Everything is working great but now I want to add a file upload, so I can add an image to the edited record. With the static upload path everything is working great, but I would like to have a dynamic path for it.
I came across this tutorial:
http://www.chronoengine.com/faqs/53-cfv4/cfv4-file-uploads/2630-how-can-i-upload-files-under-some-users-folder.html
Very helpfull, but I don't want to upload the file under some users folder, I want to upload it to the year that is used in the edit form.

In CF, in the Designer tab, I have a input field with the name "movements_ewas[year]" (without ""). This is how my date lookes in the edit form:
[attachment=0]CF_date.png[/attachment
I also have a file upload element.

In the Setup tab I have a custom code [b]before[/b] the file upload and it has this code:

<?php
$year = $form->data['movements_ewas']['year']);
$form->actions_config[3]["upload_path"] = "/home/sites/xxxx/images/movements".DS.$year.DS;
?>

In the example image above the year is 2014. So when I want to upload a file to that record, the file has to be uploaded in the 2014 folder (in images/movements). This part isn't working.

After the custom code I have a file upload. In there I left the upload_path emtpy.

So when I test my form, the filename is stored in the database, but the file isn't uploaded.
I think I am doing something wrong with the custom code....

Hope someone can help me.

Regards,
Ruud
pat01 18 Jul, 2016
Hello

I have the same problem.

In CF4 ist was possible to simply add the name of the desired field inside of curly brackets to the upload path.
Example:
uploads/{my-textfiel-name}


It worked great.

Unfortunately it's not working in CF5 anymore.
Is there any solution for this?

Thanks a lot!

Patrick
GreyHead 18 Jul, 2016
Hi Patrick,

What exactly do you need to do?

There are two ways to put an uploaded file in a custom folder.

+ you can move it after the Files Upload action, or

+ you can over-ride the default Upload Path - Max has posted some code to do this, I'd need to hunt that down in the forums.

?? It might also be possible to add a folder prefix to the file name in the File Name code box - I haven't tried that ??

Bob
pat01 18 Jul, 2016
Hi Bob

In the form I have a textfield named "lastname". I want the upload path to be like this:
images/uploads/{lastname}

where {lastname} will be replaeced with the data the user puts into the field "lastname".

In CF4 it worked like this:
[attachment=0]Unbenannt-1.jpg[/attachment]

But it's not working in CF5.

Patrick
GreyHead 18 Jul, 2016
Hi Patrick,

This seems to work.

Add a Custom Code action before the Upload Files action with code like this:
<?php
$form->actions_config[1]['upload_path'] = JPATH_SITE.'/components/com_chronoforms5/chronoforms/uploads/'.$form->form['Form']['title'].'/'.$form->data['text4'].'/';
?>

Replace the 1 with the ID of the Files Upload action - the little number just after the Files Upload label.
Replace the path with the one you need. In your case that will be something like
JPATH_SITE.'/images/uploads/'.$form->data['lastname'].'/';

Bob
pat01 19 Jul, 2016
Hi Bob

Works great, thank you very much!

Patrick
This topic is locked and no more replies can be posted.