Forums

File name from form data

ramakunga 08 Jan, 2016
I have a form that i would like to upload files with unique names based on 2 fields in the form. The values i want are stored in

$form->data[main][Incident_ID]
$form->data[main][Incident_DateReported]


The Incident ID is generated using Bobs fantastic Unique_ID[GH] Action

I would like these added along with $File_Name

so if the values were "PK8864G" for the Incident_ID and 12-12-2016 for the Date Reported I would like the file name to be

PK8864G_12-12-2016_Filename.doc

All i have managed to do is get partial values to work, any help with the syntax required to get this to work would be appreciated
GreyHead 08 Jan, 2016
Hi ramakunga,

You can use the File Name Code box in the Upload Files action to set the name. The code will be something like this
<?php
return  $form->data['main']['Incident_ID'].'_'.date('dd-mm-yyyy').'_'.$file_name;
?>

Bob
ilmagowalter 24 Feb, 2016
Hi Bob,
i up this post for my request

i have to upload a file but i want to keep the original name
what i have to write in file name code box ?
ilmagowalter 24 Feb, 2016
solved
<?php
	return $file_name;
?>

i made a sintax error before

ty
GreyHead 24 Feb, 2016
Hi ilmagowalter,

That's correct - but note that if two users both upload files with the same name e.g. my_selfie.jpg then only one will be saved (I think that the older one will be kept but I'm not certain of that).

Bob

[[>> later : I was wrong, the new file overwrites the old one <<]]
ilmagowalter 24 Feb, 2016
Hi Bob,
ty for suggest but is just i want..only one version of nomefile.jpg🙂

i will try to understand if the file keep is the older or newest
ilmagowalter 25 Feb, 2016
the new file overwrite the old😉
Henocq 03 Jul, 2016
Hi,
I want to auto-rename my upload file with an unique ID. For example test.wav to test001.wav.
How can I do this ?

thanks for the help

Julien
GreyHead 04 Jul, 2016
Hi Julien,

There are a couple of ways to do this.

By default ChronoForms uses the date+time to create a unique ID. Will that work for you?

If you want to use a serial number e.g. 001, 002 . . . then I'd suggest that you save the data to a database table, then rename the file using the new record id and update the table with the new name - that's more complicated because you don't know the new record id until after the record is created.

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