Pārlūkot izejas kodu

部署文件上传

layui
yirenyishi pirms 6 gadiem
vecāks
revīzija
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
}
//创建目录
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)
if err != nil {
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 ))
fileName := fmt.Sprintf("%x", hashName) + ext
fpath := uploadDir + fileName
urlDir += fileName
defer f.Close() //关闭上传的文件,不然的话会出现临时文件不能清除的情况
err = this.SaveToFile(filename, fpath)
if err != nil {
@ -61,6 +63,7 @@ func (this *FileController) Upload() {
this.ServeJSON()
return
}
urlDir = "https://aiprose.com/foss/" + urlDir
this.Data["json"] = models.ReurnData("", fpath)
this.ServeJSON()
return
@ -128,7 +131,6 @@ func (this *FileController) HeadImgUpload() {
this.ServeJSON()
return
}
this.SetSession("headimg", urlDir)
this.Data["json"] = models.ReurnData("", urlDir)
this.ServeJSON()
return

9
views/newblog.html

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

3
views/note.html

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

Notiek ielāde…
Atcelt
Saglabāt