module_files_act_remove_file.go 840 B

123456789101112131415161718192021222324252627282930313233343536
  1. package modules
  2. import (
  3. "os"
  4. "strings"
  5. "golang-fave/engine/utils"
  6. "golang-fave/engine/wrapper"
  7. )
  8. func (this *Modules) RegisterAction_FilesRemoveFile() *Action {
  9. return this.newAction(AInfo{
  10. Mount: "files-remove-file",
  11. WantAdmin: true,
  12. }, func(wrap *wrapper.Wrapper) {
  13. pf_file := utils.SafeFilePath(utils.Trim(wrap.R.FormValue("file")))
  14. file := strings.Join([]string{wrap.DHtdocs, "public"}, string(os.PathSeparator)) + pf_file
  15. if err := os.Remove(file); err != nil {
  16. wrap.MsgError(err.Error())
  17. return
  18. }
  19. path := "/"
  20. i := strings.LastIndex(pf_file, string(os.PathSeparator))
  21. if i != -1 {
  22. path = pf_file[:i+1]
  23. }
  24. // Set path
  25. wrap.Write(`$('#sys-modal-files-manager .dialog-path span').html('` + path + `');`)
  26. // Refresh table
  27. wrap.Write(`fave.FilesManagerLoadData('` + path + `');`)
  28. })
  29. }