diff --git a/PruebaForm/app.py b/PruebaForm/app.py new file mode 100644 index 0000000..b212a80 --- /dev/null +++ b/PruebaForm/app.py @@ -0,0 +1,36 @@ +from flask import Flask, request, redirect, url_for, render_template, flash +from werkzeug.utils import secure_filename +import os + +app = Flask(__name__, instance_relative_config=True) +app.config['UPLOAD_FOLDER'] = os.path.join(app.instance_path, 'uploads') +app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # Limitar el tamaño del archivo a 16 MB +app.config['SECRET_KEY'] = 'supersecretkey' + +# Asegúrate de que la carpeta de uploads existe +os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True) + +@app.route('/') +def index(): + return render_template('upload.html') + +@app.route('/upload', methods=['POST']) +def upload_file(): + if 'photo' not in request.files: + flash('No file part') + return redirect(request.url) + + file = request.files['photo'] + + if file.filename == '': + flash('No selected file') + return redirect(request.url) + + if file: + filename = secure_filename(file.filename) + file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) + flash('File successfully uploaded') + return redirect(url_for('index')) + +if __name__ == '__main__': + app.run(debug=True) diff --git a/PruebaForm/instance/uploads/emoji1.png b/PruebaForm/instance/uploads/emoji1.png new file mode 100644 index 0000000..6edf4b0 Binary files /dev/null and b/PruebaForm/instance/uploads/emoji1.png differ diff --git a/PruebaForm/templates/upload.html b/PruebaForm/templates/upload.html new file mode 100644 index 0000000..4fa4d38 --- /dev/null +++ b/PruebaForm/templates/upload.html @@ -0,0 +1,24 @@ + + +
+ + +