I have this Xbasic function in a UX with drag and drop upload everything works fine until I added changing the file name.
Then the files stopped uploading and I don't get any error messages either.
The idea is that I loop through the files in the target folder to find the first free number from 1 and up and use this as the file name of the
first file that I upload, then we loop to the next free number to use it as the file name of the next file .
But it doesn't work so well, the files don't arrive,
I hope someone has a couple of minutes to spare and can maybe see what I'm doing wrong.
Upload target is Alpha Anywhere (a folder on the server)
Thanks in advance
..........................................................
function Bio_Levfakt_Upload as v (e as p)
' Specify the target folder
dim targetFolder as c = "D:\Arkiv\Bio\Bio_Levfakt\Bio_Levfakt_2"
dim targetFolderFullyQualified as c
targetFolderFullyQualified = a5_removetrailingbackslash(targetFolder)
' Make sure that the target folder exists
dir_create_recurse(targetFolderFullyQualified)
' Extract the file extension
dim fileExtension as c
fileExtension = file.get_extension(e.sourceFileName)
' Generate a unique filename based on the next available number
dim availableNumber as n = 1
dim targetFilename as c
' Loop to find the next available number
while .t. ' Infinite loop until a unique filename is found
targetFilename = targetFolderFullyQualified + chr(92) + "File_" + alltrim(availableNumber) + fileExtension
if not file.exists(targetFilename) then
' Copy the temporary file to the permanent location with the new filename
file.copy2(e.localFilename, targetFilename)
' Log information or send notifications (customize this part based on your needs)
dim logMessage as c
logMessage = "File '" + e.sourceFileName + "' uploaded and saved to '" + targetFolder + "' folder as '" + file.get_name(targetFilename) + "'."
' Log to the Alpha Anywhere server log
ui_msg_box("File Upload", logMessage)
exit while ' Exit the loop once a unique filename is found
end if
availableNumber = availableNumber + 1
wend
end function
Then the files stopped uploading and I don't get any error messages either.
The idea is that I loop through the files in the target folder to find the first free number from 1 and up and use this as the file name of the
first file that I upload, then we loop to the next free number to use it as the file name of the next file .
But it doesn't work so well, the files don't arrive,
I hope someone has a couple of minutes to spare and can maybe see what I'm doing wrong.
Upload target is Alpha Anywhere (a folder on the server)
Thanks in advance
..........................................................
function Bio_Levfakt_Upload as v (e as p)
' Specify the target folder
dim targetFolder as c = "D:\Arkiv\Bio\Bio_Levfakt\Bio_Levfakt_2"
dim targetFolderFullyQualified as c
targetFolderFullyQualified = a5_removetrailingbackslash(targetFolder)
' Make sure that the target folder exists
dir_create_recurse(targetFolderFullyQualified)
' Extract the file extension
dim fileExtension as c
fileExtension = file.get_extension(e.sourceFileName)
' Generate a unique filename based on the next available number
dim availableNumber as n = 1
dim targetFilename as c
' Loop to find the next available number
while .t. ' Infinite loop until a unique filename is found
targetFilename = targetFolderFullyQualified + chr(92) + "File_" + alltrim(availableNumber) + fileExtension
if not file.exists(targetFilename) then
' Copy the temporary file to the permanent location with the new filename
file.copy2(e.localFilename, targetFilename)
' Log information or send notifications (customize this part based on your needs)
dim logMessage as c
logMessage = "File '" + e.sourceFileName + "' uploaded and saved to '" + targetFolder + "' folder as '" + file.get_name(targetFilename) + "'."
' Log to the Alpha Anywhere server log
ui_msg_box("File Upload", logMessage)
exit while ' Exit the loop once a unique filename is found
end if
availableNumber = availableNumber + 1
wend
end function
Comment