Skip to content

Instantly share code, notes, and snippets.

@nickdavies791
Created February 7, 2020 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickdavies791/0db4600795424017762abeb5c4fa7165 to your computer and use it in GitHub Desktop.
Save nickdavies791/0db4600795424017762abeb5c4fa7165 to your computer and use it in GitHub Desktop.
#########################################################
##
## 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