Compare commits
No commits in common. "304a5911e274a12f9793d2a615db3cda93c22663" and "4b8954d540f7263a0aea4352ae3d4f46dcf8f4dd" have entirely different histories.
304a5911e2
...
4b8954d540
2 changed files with 7 additions and 20 deletions
21
go/main.go
21
go/main.go
|
@ -91,6 +91,7 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Zurücksetzen des Dateizeigers, um die Datei vollständig zu kopieren
|
||||||
_, err = file.Seek(0, io.SeekStart)
|
_, err = file.Seek(0, io.SeekStart)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Fehler beim Zurücksetzen des Dateizeigers", http.StatusInternalServerError)
|
http.Error(w, "Fehler beim Zurücksetzen des Dateizeigers", http.StatusInternalServerError)
|
||||||
|
@ -98,20 +99,8 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ermitteln, ob der ursprüngliche Dateiname erzwungen werden soll
|
// Hier können Sie den Dateinamen manipulieren oder einen anderen Speicherort wählen
|
||||||
//forceName := r.Header.Get("Force-Name")
|
uploadPath := "./uploads/" + handler.Filename
|
||||||
forceName := r.FormValue("force_name")
|
|
||||||
var filename string
|
|
||||||
if forceName == "true" {
|
|
||||||
filename = handler.Filename
|
|
||||||
} else {
|
|
||||||
// Zeitstempel zum Dateinamen hinzufügen
|
|
||||||
timestamp := time.Now().Format("20060102-150405")
|
|
||||||
filename = fmt.Sprintf("%s-%s", timestamp, handler.Filename)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Datei speichern
|
|
||||||
uploadPath := "./uploads/" + filename
|
|
||||||
f, err := os.Create(uploadPath)
|
f, err := os.Create(uploadPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Fehler beim Erstellen der Datei", http.StatusInternalServerError)
|
http.Error(w, "Fehler beim Erstellen der Datei", http.StatusInternalServerError)
|
||||||
|
@ -129,6 +118,7 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
lastUploadTime = time.Now() // Setzen Sie die Zeit des letzten Uploads
|
lastUploadTime = time.Now() // Setzen Sie die Zeit des letzten Uploads
|
||||||
|
|
||||||
|
// Nach erfolgreichem Upload:
|
||||||
tmpl, err := template.ParseFiles("templates/uploadSuccess.html")
|
tmpl, err := template.ParseFiles("templates/uploadSuccess.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Fehler beim Laden des Templates", http.StatusInternalServerError)
|
http.Error(w, "Fehler beim Laden des Templates", http.StatusInternalServerError)
|
||||||
|
@ -141,7 +131,7 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
Filename string
|
Filename string
|
||||||
}{
|
}{
|
||||||
Message: "Bild erfolgreich hochgeladen.",
|
Message: "Bild erfolgreich hochgeladen.",
|
||||||
Filename: filename, // Geändert, um den möglicherweise modifizierten Dateinamen anzuzeigen
|
Filename: handler.Filename,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = tmpl.Execute(w, data)
|
err = tmpl.Execute(w, data)
|
||||||
|
@ -152,6 +142,7 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles("templates/uploadForm.html")
|
tmpl, err := template.ParseFiles("templates/uploadForm.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Fehler beim Laden des Templates", http.StatusInternalServerError)
|
http.Error(w, "Fehler beim Laden des Templates", http.StatusInternalServerError)
|
||||||
|
|
|
@ -5,11 +5,7 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<form action="/upload" method="post" enctype="multipart/form-data">
|
<form action="/upload" method="post" enctype="multipart/form-data">
|
||||||
<input type="file" name="image" required>
|
<input type="file" name="image">
|
||||||
<br>
|
|
||||||
<input type="checkbox" name="force_name" value="true">
|
|
||||||
<label for="force_name">Originalnamen beibehalten (Force Name)</label>
|
|
||||||
<br>
|
|
||||||
<input type="submit" value="Hochladen">
|
<input type="submit" value="Hochladen">
|
||||||
</form>
|
</form>
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Reference in a new issue