Browse Source

部署文件上传

layui
yirenyishi 6 years ago
parent
commit
58eea15152
  1. 6
      controllers/FileController.go
  2. 9
      views/newblog.html
  3. 3
      views/note.html

6
controllers/FileController.go

@ -40,7 +40,8 @@ func (this *FileController) Upload() {
return return
} }
//创建目录 //创建目录
uploadDir := "static/upload/" + time.Now().Format("2006/01/02/") urlDir := time.Now().Format("2006/01/02/")
uploadDir := "/opt/filetom/webapps/itstack/" + urlDir
err := os.MkdirAll(uploadDir, 777) err := os.MkdirAll(uploadDir, 777)
if err != nil { if err != nil {
this.Data["json"] = models.ReurnError(500, "") this.Data["json"] = models.ReurnError(500, "")
@ -53,6 +54,7 @@ func (this *FileController) Upload() {
hashName := md5.Sum([]byte( time.Now().Format("2006_01_02_15_04_05_") + randNum )) hashName := md5.Sum([]byte( time.Now().Format("2006_01_02_15_04_05_") + randNum ))
fileName := fmt.Sprintf("%x", hashName) + ext fileName := fmt.Sprintf("%x", hashName) + ext
fpath := uploadDir + fileName fpath := uploadDir + fileName
urlDir += fileName
defer f.Close() //关闭上传的文件,不然的话会出现临时文件不能清除的情况 defer f.Close() //关闭上传的文件,不然的话会出现临时文件不能清除的情况
err = this.SaveToFile(filename, fpath) err = this.SaveToFile(filename, fpath)
if err != nil { if err != nil {
@ -61,6 +63,7 @@ func (this *FileController) Upload() {
this.ServeJSON() this.ServeJSON()
return return
} }
urlDir = "https://aiprose.com/foss/" + urlDir
this.Data["json"] = models.ReurnData("", fpath) this.Data["json"] = models.ReurnData("", fpath)
this.ServeJSON() this.ServeJSON()
return return
@ -128,7 +131,6 @@ func (this *FileController) HeadImgUpload() {
this.ServeJSON() this.ServeJSON()
return return
} }
this.SetSession("headimg", urlDir)
this.Data["json"] = models.ReurnData("", urlDir) this.Data["json"] = models.ReurnData("", urlDir)
this.ServeJSON() this.ServeJSON()
return return

9
views/newblog.html

@ -33,8 +33,14 @@
var storage=window.localStorage var storage=window.localStorage
var E = window.wangEditor var E = window.wangEditor
var editor = new E('#editor') var editor = new E('#editor')
editor.customConfig.uploadImgServer = '/upload' editor.customConfig.uploadImgServer = '/file/upload'
// 或者 var editor = new E( document.getElementById('editor') ) // 或者 var editor = new E( document.getElementById('editor') )
editor.customConfig.uploadImgHooks = {
customInsert: function (insertImg, result, editor) {
insertImg(result.Data);
debugger
}
}
editor.create() editor.create()
document.onkeydown = keyDown; document.onkeydown = keyDown;
@ -42,7 +48,6 @@
var currKey = 0, e = e || event || window.event; var currKey = 0, e = e || event || window.event;
currKey = e.keyCode || e.which || e.charCode; currKey = e.keyCode || e.which || e.charCode;
if (currKey == 83 && (e.ctrlKey || e.metaKey)) { if (currKey == 83 && (e.ctrlKey || e.metaKey)) {
layer.msg("ctrl+s")
saveBlog() saveBlog()
return return
} }

3
views/note.html

@ -88,8 +88,7 @@
// 或者 var editor = new E( document.getElementById('editor') ) // 或者 var editor = new E( document.getElementById('editor') )
editor.customConfig.uploadImgHooks = { editor.customConfig.uploadImgHooks = {
customInsert: function (insertImg, result, editor) { customInsert: function (insertImg, result, editor) {
var url = result.Data.replace("static/upload", "https://airose.com/itstack"); insertImg(result.Data);
insertImg(url);
debugger debugger
} }
} }

Loading…
Cancel
Save