Buy Now
Sign in

Creating a filename based on a form data field value for an upload.

earthwatch , March 06 2018, 16:31
E
earthwatch 23
March 06 2018, 16:31 #375906
Hi,
I have read through the manual and other posts but can not find the answer.
I have a form with 2 field upload options. I would like the file names to have the date and time stamp followed by the first-name and last-name data fields follwoed by the actual name and extension.
If my first name ID is first-name and my last name ID is last-name, how would I write the variable in the 'File name provider' field? I see you can use {var:FN.file.name} and {var:FN.file.extension} but not sure how I combine that to end up with:
{datestamp}{first-name}{last-name}{filename}{file extension}
Thanks a lot
Paul.
admin 28
March 07 2018, 03:50 #375911
Hi Paul,
You should use the field name but not id, you would need something like this:
{date:YmdHis}{data:first_name}{data:last_name}{var:upload_name.file.name}{var:upload_name.file.extension}
Best regards
Max
If your main question got answered then please mark the answer using the button!
Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
E
earthwatch 23
March 07 2018, 08:51 #375916
Hi Max, so I added the var that you suggested, using the field name in the 'File name provider' field and I got the following:
The 2 files that were uploaded were:
Earthwatch.txt - ended up being '20180307083954PaulSpyker'
logo.jpg - ended up being '20180306155708_logo.jpg'
So the first file was renamed but did not have the extension nor did it keep the original file name.
The second file was not affected and kept the standard naming convention.
My aim is to rename both the files as you have suggested above.
I look forward to your response,
Paul.
admin 28
March 07 2018, 13:59 #375922
Hi Paul,
The "upload_name" in the string should be replaced by the name of the "upload files" action.
How many file upload actions do you have ?
Best regards
Max
If your main question got answered then please mark the answer using the button!
Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
E
earthwatch 23
March 07 2018, 15:02 #375925
Hi, there are just two files that they can upload, the first is required and the second is not required.
Thanks
Paul.
E
earthwatch 23
March 07 2018, 15:11 #375926
Hi Max, that all works, great thank you. Just one last question, if I want to put a hyphen in between the firstname and lastname, is that possible and if so what would the code be in the below:
{date:YmdHis}{data:first_name}{data:last_name}{var:upload2.file.name}{var:upload2.file.extension}
Thanks
Paul.
admin 28
March 08 2018, 02:45 #375935
 1
 Answer
Hi Paul,
Great, so the string would be:
{date:YmdHis}{data:first_name}_{data:last_name}{var:upload2.file.name}{var:upload2.file.extension}
Best regards
Max
If your main question got answered then please mark the answer using the button!
Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
E
earthwatch 23
March 08 2018, 10:35 #375942
 1
Hi Max, perfect, thanks. I noticed you have to add a . between the last 2 variables else the file extension is part of the filename, but I have added the following and it all works perfectly:
Thanks a lot for your support!
Paul.
{date:YmdHis}_{data:first_name}_{data:last_name}_{var:upload2.file.name}.{var:upload2.file.extension}
admin 28
March 08 2018, 14:13 #375946
Hi Paul,
Good catch!
Best regards
Max
If your main question got answered then please mark the answer using the button!
Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
G
GKCE3U 2
November 03 2018, 17:10 #381245
Hello everyone
i join this thread because I'm having some difficulties just in creating file names in a form with multiple uploads.
I need to remove specific characters (minus, underscore, spaces and points) from the names of the uploaded files.

for example the file: 2018-10-01_document aaa.pdf
I have to transform it into: 20181001documentaaa.pdf

I tried using custom php code, that I called strreplace, and I get an array containing the correct file names but I get an error when I insert it {var:strreplace} in File name provider.

result example:
Warning: move_uploaded_file(C:\xampp\htdocs\xxxx\components\com_chronoforms6\chronoforms\uploads\["20181001documentaaa","20181001documentbbb","20181001documentccc"].pdf): failed to open stream: No such file or directory in C:\xampp\htdocs\xxx\libraries\cegcore2\libs\upload.php on line 31

Where am I wrong?

Can I use an alternative method?

Thank you

healyhatman 8
November 04 2018, 07:28 #381252
You can use a loop event and do the file upload one by one
Web developer at SkySpider.com.au - I DO NOT work for ChronoEngine!
Donations: paypal.me/healyhatman
Professional Work: kamron@skyspider.com.au
Custom CF / CC Plugins and Extensions: skyspider.com.au/store