I would like to rename my files based on some variable field names.
For example:
I have one file field name "file1", and another named "file2", and would like to rename the files to:
file1_DATE_FILENAME and file2_DATE_FILENAME
What I've done so far is to create two actions and setting the renaming in the action and it works great, but this was just for an example, because in the actual form I will need to rename about 50 file fields and would like to have a dynamic way to do it.
What I've tried:
(in the upload action renaming section)
As you can see in my code:
I have no idea of how to get the current field in the upload action.
How do I solve this?
For example:
I have one file field name "file1", and another named "file2", and would like to rename the files to:
file1_DATE_FILENAME and file2_DATE_FILENAME
What I've done so far is to create two actions and setting the renaming in the action and it works great, but this was just for an example, because in the actual form I will need to rename about 50 file fields and would like to have a dynamic way to do it.
What I've tried:
(in the upload action renaming section)
<?php
//depending on the field name, it will name it according to the promoter, this way we save nine actions!
//promot_1, check the 8th character
$promoID = $form->data(HOW_TO_GET_THIS?);
return $promoID . "_" . date("YmdHis") . "_" . $file_name;
?>
As you can see in my code:
$form->data(HOW_TO_GET_THIS?)
I have no idea of how to get the current field in the upload action.
How do I solve this?
Hi htavares,
It's a bit crude but I solved this recently by using the $file_name to look up the value in the $_FILES array,
Bob
It's a bit crude but I solved this recently by using the $file_name to look up the value in the $_FILES array,
foreach ( $_FILES as $k => $v ) {
$temp = str_replace(' ', '_', $v['name']);
if ( $temp == $file_name ) {
. . . // do something
continue;
}
}
This lets you find the name of the current upload field . . . **provided** that the uploaded file names are all different.
Bob
Thanks for the quick reply Bob!
That method is a good start, but I can't rely on having different file names (not to mention not knowing the actual file name that Chronoforms "transformed", that str_replace that you have is not enough for what it does to filenames with accents, is it not?).
Is there a way to get something like $form->data[this] ?
That method is a good start, but I can't rely on having different file names (not to mention not knowing the actual file name that Chronoforms "transformed", that str_replace that you have is not enough for what it does to filenames with accents, is it not?).
Is there a way to get something like $form->data[this] ?
Hi htavares,
Is there a way to get something like $form->data[this] ?
Not that I know of.
There are two functions used on the file name either utf8_decode() or
Bob
Is there a way to get something like $form->data[this] ?
Not that I know of.
There are two functions used on the file name either utf8_decode() or
preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $filename);
if the make safe option is checked.
Bob
This topic is locked and no more replies can be posted.