Buy Now
Sign in

File upload: input field in dynamic Path

flyboeing , November 06 2015, 10:02
F
flyboeing 150
November 06 2015, 10:02 #353213
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 before 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
Attachments
CF_date.png
CF_date.png
(1.82 KiB)
1337 Downloads/Views
pat01 301
July 18 2016, 14:34 #360738
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 65
July 18 2016, 14:57 #360744
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
If you'd like to buy me a coffee or two, thank you very much
pat01 301
July 18 2016, 15:15 #360749
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:
Unbenannt-1.jpg

But it's not working in CF5.

Patrick
Attachments
Unbenannt-1.jpg
Unbenannt-1.jpg
(55.71 KiB)
1537 Downloads/Views
GreyHead 65
July 18 2016, 15:41 #360751
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
If you'd like to buy me a coffee or two, thank you very much
pat01 301
July 19 2016, 08:38 #360762
Hi Bob

Works great, thank you very much!

Patrick