ChronoEngine.com homepage

Forums

Please write a review for the extension you are using on the Joomla extensions directory before posting a new question as we are being spammed by many negative reviews.

Thank you for your support!

Upload files using filname generator

healyhatman 15 Jul, 2017
EDIT: SOLVED -> Here's the rambling innefficient solution I devised with some thanks to Max.

Let's say we have a file field called myFile on the form.
Generate part of the filename using a Modify Data action, which we will call fileNameGenerator and set the data provider field to whatever you need, e.g. {user:name}_{rand:} - this step is required if you want all the files uploaded to your server in this form submission to have the same string in their name

If you want the field name to be in the uploaded file name you'll need an upload file action for each field.
For each field that needs a unique name, you need a separate upload action (for some reason).
Set File name provider in your upload action to {var:fileNameGenerator}<whatever else you want>.{var:<name of your upload action>.file.extension}

So if my upload action is named (the black label) upload54, and my file field is called myFile, and I want my file uploaded to the server as <user name>_<a random number>_<the name of the file field>.<the file extension> then it would be {user:name}_{rand:}_<the name of the file field>.{var:upload54.file.extension} or I can put {var:fileNameGenerator} in there somewhere to use the string we generated earlier.

USING IT IN PHP

OK so you've uploaded the file to the server and now for whatever reason you want to access it in a PHP action (which has to come AFTER the file upload action!).

$this->get("<file upload action>", ""); which gives us an array of field names, with each field name being another array with the uploaded path, the filename, the name of the original file as uploaded by the user, and the size.

So if I want to get the full path of the uploaded image as it is on my server, with an upload action called upload5 and a file field called myFile, I would use $this->get('upload5', '')['myFile']['path']

=========================================
Original message


I have a Modify Data action that generates a prefix using {data:firstName}_{data:lastName}_{uuid:} that I access using {var:fileNameGenerator}.
I have several file fields. Let's call the fields alphaField, betaField, deltaField.

When uploading the files to the server, I want them called {var:fileNameGenerator}_fieldName.extension

Help would be appreciated.
Max_admin 15 Jul, 2017
Hello healyhatman,

You can customize the uploaded file name using the "File name provider" in the upload action, you can use {var:upload_action_name.extension} to get the file's extension.

Best regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
healyhatman 17 Jul, 2017
How do I get the -->FIELD<-- name though?
Max_admin 18 Jul, 2017
Hi healyhatman,

You mean the "file name" ? please use {var:upload_action_name.file.name} for name and {var:upload_action_name.file.extension} for file's extension.

Best regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
healyhatman 18 Jul, 2017
No I mean the field name, that's why I had "field" in all caps with big arrows pointing to it.

So let's say I have a file field I have named "penis". A user called Andrew uploads a file called "vagina.jpeg".
I have another field, named "orange". Andrew uploads a file called "apple.jpeg".

I want the files to be uploaded to my server to be named Andrew_penis.jpeg and Andrew_orange.jpeg

The FIELD names.
Max_admin 19 Jul, 2017
H healyhatman,

No way to get the field name inside that box, you can use an upload action for each field and use the field name in the provider syntax.

Best regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
This topic is locked and no more replies can be posted.

2Checkout.com

2CheckOut.com Inc. (Ohio, USA) is an authorized retailer for goods and services provided by ChronoEngine.com