This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
######################################################### | |
## | |
## Uploads a file to a given folder and renames. | |
## | |
######################################################### | |
Funprog UPLOAD_FILE_AND_RENAME(TEMPDIR, FILDIR, FILNAM, NEWNAM) | |
Variable Char TEMPDIR, FILDIR, FILNAM, NEWNAM | |
Local Integer COPYSTA | |
Local Integer MOVESTA | |
#---------------------------------------------------- | |
# Copy the uploaded file to the temporary folder | |
#---------------------------------------------------- | |
COPYDIR = filpath("tmp", "", "") | |
Call COPSRV(FILNAM, COPYDIR, COPYSTA) From ORDSYS | |
If COPYSTA <> 0 | |
Call ERREUR("The file could not be copied to the server.") From GESECRAN | |
End COPYSTA | |
Endif | |
#---------------------------------------------------- | |
# Move from temp folder to another folder so to | |
# avoid any potential name conflicts when renaming | |
#---------------------------------------------------- | |
CURPATH = COPYDIR+"\"+FILNAM | |
MOVEDIR = filpath(TEMPDIR, "", "") | |
Call MOVE(CURPATH, MOVEDIR, MOVESTA) From ORDSYS | |
If MOVESTA <> 0 | |
Call ERREUR("The file could not be moved to the temporary folder.") From GESECRAN | |
End MOVESTA | |
Endif | |
RENAMSTA = func RENAME_FILE(TEMPDIR, FILNAM, NEWNAM) | |
If RENAMSTA <> 0 | |
Call ERREUR("The file could not be renamed.") From GESECRAN | |
End RENAMSTA | |
Endif | |
#---------------------------------------------------- | |
# Move from temp folder to main folder | |
#---------------------------------------------------- | |
FILNAMEXT = mid$(FILNAM, instr(1, FILNAM, "." ), 99) | |
CURPATH = MOVEDIR+"\"+NEWNAM+FILNAMEXT | |
NEWPATH = filpath(FILDIR, "", "") | |
Call MOVE(CURPATH, NEWPATH, MOVESTA) From ORDSYS | |
If MOVESTA <> 0 | |
Call ERREUR("The file could not be moved to the new folder.") From GESECRAN | |
End MOVESTA | |
Endif | |
End COPYSTA |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment