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
|
||||
}
|
||||
|
||||
// Zurücksetzen des Dateizeigers, um die Datei vollständig zu kopieren
|
||||
_, err = file.Seek(0, io.SeekStart)
|
||||
if err != nil {
|
||||
http.Error(w, "Fehler beim Zurücksetzen des Dateizeigers", http.StatusInternalServerError)
|
||||
|
@ -98,20 +99,8 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
// Ermitteln, ob der ursprüngliche Dateiname erzwungen werden soll
|
||||
//forceName := r.Header.Get("Force-Name")
|
||||
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
|
||||
// Hier können Sie den Dateinamen manipulieren oder einen anderen Speicherort wählen
|
||||
uploadPath := "./uploads/" + handler.Filename
|
||||
f, err := os.Create(uploadPath)
|
||||
if err != nil {
|
||||
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
|
||||
|
||||
// Nach erfolgreichem Upload:
|
||||
tmpl, err := template.ParseFiles("templates/uploadSuccess.html")
|
||||
if err != nil {
|
||||
http.Error(w, "Fehler beim Laden des Templates", http.StatusInternalServerError)
|
||||
|
@ -141,7 +131,7 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
|||
Filename string
|
||||
}{
|
||||
Message: "Bild erfolgreich hochgeladen.",
|
||||
Filename: filename, // Geändert, um den möglicherweise modifizierten Dateinamen anzuzeigen
|
||||
Filename: handler.Filename,
|
||||
}
|
||||
|
||||
err = tmpl.Execute(w, data)
|
||||
|
@ -152,6 +142,7 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
} else {
|
||||
|
||||
tmpl, err := template.ParseFiles("templates/uploadForm.html")
|
||||
if err != nil {
|
||||
http.Error(w, "Fehler beim Laden des Templates", http.StatusInternalServerError)
|
||||
|
|
|
@ -5,11 +5,7 @@
|
|||
</head>
|
||||
<body>
|
||||
<form action="/upload" method="post" enctype="multipart/form-data">
|
||||
<input type="file" name="image" required>
|
||||
<br>
|
||||
<input type="checkbox" name="force_name" value="true">
|
||||
<label for="force_name">Originalnamen beibehalten (Force Name)</label>
|
||||
<br>
|
||||
<input type="file" name="image">
|
||||
<input type="submit" value="Hochladen">
|
||||
</form>
|
||||
</body>
|
||||
|
|
Loading…
Reference in a new issue