Forums

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

earthwatch 06 Mar, 2018
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.
Max_admin 07 Mar, 2018
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, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
earthwatch 07 Mar, 2018
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.
Max_admin 07 Mar, 2018
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, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
earthwatch 07 Mar, 2018
Hi, there are just two files that they can upload, the first is required and the second is not required.

Thanks
Paul.
earthwatch 07 Mar, 2018
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.
Max_admin 08 Mar, 2018
Answer
1 Likes
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, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
earthwatch 08 Mar, 2018
1 Likes
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}
Max_admin 08 Mar, 2018
Hi Paul,

Good catch!

Best regards
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GKCE3U 03 Nov, 2018
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 04 Nov, 2018
You can use a loop event and do the file upload one by one
This topic is locked and no more replies can be posted.