Skip to content

Commit

Permalink
will make remake dir if does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Mole1424 committed Jun 12, 2024
1 parent 3d75061 commit ff60b59
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from functools import wraps
from logging import INFO, basicConfig, info, warning
from os import environ, getenv, path, getcwd, remove
from os import environ, getenv, path, getcwd, makedirs

from flask import Flask, redirect, render_template, request, session
from flask_limiter import Limiter
Expand All @@ -13,7 +13,7 @@

from db_schema import Projects, db

dev = False # if true then uses config.txt to set environment variables
dev = True # if true then uses config.txt to set environment variables
if dev:
with open("config.txt", "r") as f:
for line in f.readlines():
Expand Down Expand Up @@ -309,6 +309,11 @@ def upload_photo():
# set up initial (secure) filepath
filename = secure_filename(photo.filename)
filepath = path.join(getcwd(), app.config["UPLOAD_FOLDER"][1:], filename)

# create directory if it doesn't exist
if not path.exists(path.dirname(filepath)):
makedirs(path.dirname(filepath))

# if file already exists then add a number to the start of the filename
i = 1
while path.exists(filepath):
Expand Down

0 comments on commit ff60b59

Please sign in to comment.