images with same file name wont overwrite each other
This commit is contained in:
@@ -774,7 +774,18 @@ def assets():
|
||||
if "image" in request.files:
|
||||
file = request.files["image"]
|
||||
filename = file.filename
|
||||
file.save(os.path.join(current_app.config["MISC_UPLOAD_FOLDER"], filename))
|
||||
fname, ftype = filename.split(".")
|
||||
|
||||
i = 0
|
||||
if os.path.exists(os.path.join(current_app.config["MISC_UPLOAD_FOLDER"], filename)):
|
||||
i = 2
|
||||
while os.path.exists(os.path.join(current_app.config["MISC_UPLOAD_FOLDER"], fname+str(i)+"."+ftype)):
|
||||
i += 1
|
||||
|
||||
if i == 0:
|
||||
file.save(os.path.join(current_app.config["MISC_UPLOAD_FOLDER"], filename))
|
||||
else:
|
||||
file.save(os.path.join(current_app.config["MISC_UPLOAD_FOLDER"], fname+str(i)+"."+ftype))
|
||||
|
||||
icons = db.execute("SELECT * FROM icons").fetchall()
|
||||
icon_storage = os.listdir(current_app.config["ICON_UPLOAD_FOLDER"])
|
||||
|
||||
Reference in New Issue
Block a user