Fix file upload

This commit is contained in:
James Wang 2016-01-03 19:02:58 +00:00
parent 6e6c35a222
commit 3dc40ea3dc
7 changed files with 4 additions and 13 deletions

2
.gitignore vendored
View file

@ -2,7 +2,7 @@
.secret_key .secret_key
.bundle/config .bundle/config
logs/ logs/
uploads/ files/
# Object files # Object files
*.o *.o

View file

@ -37,14 +37,9 @@ def problem_add():
if len(filename) == 0: if len(filename) == 0:
continue continue
folder = problem.name.replace(" ", "-") file_path = os.path.join(app.config["UPLOAD_FOLDER"], filename)
folder_path = os.path.join(os.path.normpath(app.config["UPLOAD_FOLDER"]), folder)
if not os.path.exists(folder_path):
os.makedirs(folder_path)
file_path = os.path.join(folder_path, filename)
_file.save(file_path) _file.save(file_path)
db_file = Files(problem.pid, file_path) db_file = Files(problem.pid, "/".join(file_path.split("/")[2:]))
db.session.add(db_file) db.session.add(db_file)
db.session.commit() db.session.commit()

View file

@ -15,7 +15,7 @@ SECRET_KEY = key
SQLALCHEMY_DATABASE_URI = "mysql://root:i_hate_passwords@localhost/easyctf" SQLALCHEMY_DATABASE_URI = "mysql://root:i_hate_passwords@localhost/easyctf"
SQLALCHEMY_TRACK_MODIFICATIONS = False SQLALCHEMY_TRACK_MODIFICATIONS = False
UPLOAD_FOLDER = os.path.normpath("files") UPLOAD_FOLDER = os.path.normpath("../web/files")
CTF_BEGIN = 0 # To be used later CTF_BEGIN = 0 # To be used later
CTF_END = 0 # To be used later CTF_END = 0 # To be used later

View file

@ -1 +0,0 @@
This is hard! I'm telling you!

View file

@ -1 +0,0 @@
Binary is not fun at all!

View file

@ -1 +0,0 @@
This is an example file, and should be removed before the tournament starts.

View file

@ -1 +0,0 @@
Hello World! How art thou?