Hi, I have a form for uploading multiple files. I need to rename the files according to a specific nomenclature that I obtain through the data and variables entered in the "File name provider" field. The variable {var: upload1.file.name} makes up a part of the entire file name. I noticed that some users upload files that have names with spaces, special characters, minus sing ecc. that I would like to delete.
For example, if a file with the name "file_1 annex-1 (copy 1) .docx" is uploaded, how can I turn it into "file1annex1copy1"?
Thank you
Thanks, through php code (which I called cleanname) I managed to get the file name without special characters. Now, however, if in the "File name provider" I use the variable {var:cleanname} I get the file name in square brackets eg.["Nomefileclean"].docx
How can I get the filename only?
Thank you
Hi GKCE3U,
I'm guessing that your PHP may be creating an array rather than a string???
Bob
Hi Bob,
The array is created because I allow multiple file uploads, so I set the "multi file selected?" to yes and the name of the file field ends with square brackets (filename[]).
With the php code I called rename, I take the filenames, delete the special characters and return an array variable.
This is the php code:
$inputFileName = $this->data("filename");
$search = ['_','-','+',' ','.','(',')','doc','docx'];
$cleanName = str_replace($search,'', $inputFileName);
return $cleanName;
In this case if the input uploaded files are:
(1) test_abcdefgh(copy 1).docx
(2) test_abcdefgh_2.docx
(3) test_abcdefgh.3.docx
the array variable $cleanName contain:
array(3) { [0]=> string(13) "testabcdefgh1" [1]=> string(13) "testabcdefgh2" [2]=> string(13) "testabcdefgh3" }
Now, I would like to rename the files as follows:
userid_cleanName.docx
ex:
700_testabcdefgh1.docx
700_testabcdefgh2.docx
700_testabcdefgh3.docx
I don't understand the correct syntax that I have to use in the "File name provider".
I've tried this
{user:id}_{var:rename.cleanName}.{var:upload3.file.extension}
{user:id}_{var:cleanName}.{var:upload3.file.extension}
but it doesn't work, the results are: 700_.docx
Could you help me?
Thank you.
GKCE3U
I can add a solution for this in v7, but of course you will need to remake this form in v7, if this is something you are interested in then please let us know!
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.