Compare commits
2 commits
4b8954d540
...
304a5911e2
Author | SHA1 | Date | |
---|---|---|---|
304a5911e2 | |||
40ea8d95df |
2 changed files with 20 additions and 7 deletions
21
go/main.go
21
go/main.go
|
@ -91,7 +91,6 @@ 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)
|
||||||
|
@ -99,8 +98,20 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hier können Sie den Dateinamen manipulieren oder einen anderen Speicherort wählen
|
// Ermitteln, ob der ursprüngliche Dateiname erzwungen werden soll
|
||||||
uploadPath := "./uploads/" + handler.Filename
|
//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
|
||||||
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)
|
||||||
|
@ -118,7 +129,6 @@ 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)
|
||||||
|
@ -131,7 +141,7 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
Filename string
|
Filename string
|
||||||
}{
|
}{
|
||||||
Message: "Bild erfolgreich hochgeladen.",
|
Message: "Bild erfolgreich hochgeladen.",
|
||||||
Filename: handler.Filename,
|
Filename: filename, // Geändert, um den möglicherweise modifizierten Dateinamen anzuzeigen
|
||||||
}
|
}
|
||||||
|
|
||||||
err = tmpl.Execute(w, data)
|
err = tmpl.Execute(w, data)
|
||||||
|
@ -142,7 +152,6 @@ 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,7 +5,11 @@
|
||||||
</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">
|
<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="submit" value="Hochladen">
|
<input type="submit" value="Hochladen">
|
||||||
</form>
|
</form>
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Reference in a new issue