Rename Uploaded Files
#1
Posted 31 October 2017 - 05:11 PM
For example: John Smith opens a new new form and its automatically assigned Unique_ID number 857, he then proceeds to upload files ashdkhsa.pdf, 546asw.doc, and jshh232h_64.jpg. The files should be renamed 857_JohnSmith_01.pdf, 857_JohnSmith_02.doc, and 857_JohnSmith_03.jpg respectively.
ashdkhsa.pdf = 857_JohnSmith_01.pdf
546asw.doc = 857_JohnSmith_02.doc
jshh232h_64.jpg = 857_JohnSmith_03.jpg
I already looked at this page but I'm not sure how to obtain the extension for each individual file, or how to add the file number.
Thank you!
#2
Posted 31 October 2017 - 08:36 PM
The only flaw here is that this code normally to be placed to BeforeAdd/BeforeEdit events where your Unique ID number is not generated yet. Typically autoincrement number are generated by the database when record is added and not before that.
Sergey Kornilov
#3
Posted 31 October 2017 - 08:58 PM
admin, on 31 October 2017 - 12:36 PM, said:
The only flaw here is that this code normally to be placed to BeforeAdd/BeforeEdit events where your Unique ID number is not generated yet. Typically autoincrement number are generated by the database when record is added and not before that.
I cant connect to that page, I get a 404 error. But I assume is the same page I meant to link on my original post but forgot. https://xlinesoft.co...oaded_files.htm
i.NoLim, on 31 October 2017 - 09:11 AM, said:
I tried using that code but I get the following error.
Quote
And this code could not be added in the "After record added" event?
Edit: I managed to open the link using a different browser, will post when I have updates.
#4
Posted 31 October 2017 - 10:30 PM
It is also possible to implement a similar technique in events like AfterAdd and AfterEdit. Instead of assigning a value to values("fieldname") you will need to build and execute a SQL query that updates "fieldname" field in the database.
Sergey Kornilov
#5
Posted 31 October 2017 - 10:42 PM
https://imgur.com/vWgGILc
https://imgur.com/a/jBPM6
#6
Posted 31 October 2017 - 11:01 PM
admin, on 31 October 2017 - 02:30 PM, said:
It is also possible to implement a similar technique in events like AfterAdd and AfterEdit. Instead of assigning a value to values("fieldname") you will need to build and execute a SQL query that updates "fieldname" field in the database.
That makes sense but will this change the name of the actual file or just the name that is displayed, as mentioned in the link you provided.
#8
Posted 01 November 2017 - 05:53 PM
admin, on 01 November 2017 - 07:07 AM, said:
My apologies, is there a way I can get this thread moved? Or is it easier for me to close it and reopen it in the ASPRunner.NET forums?
I'm attempting to write the SQL query but its proving to be more difficult than originally thought, specially for entries with multiple upload files.
#9
Posted 02 November 2017 - 05:38 PM
int j = 1 int x = count "{" in "UPLOAD_FILE" for(int i = 1; i <= x; i++) { substring_index(substring_index(UPLOAD_FILE, "{", i), "}", i) as part_j; replace([UPLOAD_FILE, substring_index(substring_index(part_j, "_", 1), "/", -1), [UNIQUE_ID]) j++; }
This is what my UPLOAD_FILE field looks like:
[{"name":"C:\\Users\\username\\Documents\\Uploads/abcd_udod4v5p.jpg","usrName":"abcd.jpg","size":1013329,"type":"image/jpeg","searchStr":"abcd.jpg,!12345.txt,!:sStrEnd"},{"name":"C:\\Users\\username\\Documents\\Uploads/12345_o6sq520f.txt","usrName":"12345.txt","size":288,"type":"text/plain"}]
#10
Posted 08 November 2017 - 09:33 PM
https://www.xlinesof...oaded_files.htm



