30 lines
830 B
Python
30 lines
830 B
Python
from flask import Flask, render_template, request, jsonify, make_response
|
|
import os
|
|
|
|
app = Flask(__name__)
|
|
UPLOAD_FOLDER = 'uploads'
|
|
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
|
|
|
|
@app.route('/')
|
|
def upload_form():
|
|
return render_template('upload.html')
|
|
|
|
@app.route('/upload', methods=['POST'])
|
|
def upload_file():
|
|
folder_number = request.form['roll_number']
|
|
images = request.files.getlist('images[]')
|
|
|
|
folder_path = os.path.join(app.config['UPLOAD_FOLDER'], folder_number)
|
|
os.makedirs(folder_path, exist_ok=True)
|
|
|
|
for image in images:
|
|
if image.filename == '':
|
|
continue
|
|
filename = image.filename
|
|
image.save(os.path.join(folder_path, filename))
|
|
|
|
return make_response(jsonify('success'), 200)
|
|
|
|
if __name__ == '__main__':
|
|
app.run(debug=True, host="0.0.0.0", port=5005)
|