SHARE
TWEET

Untitled

a guest Sep 16th, 2019 107 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def allowed_file(filename):
  2.     return '.' in filename and \
  3.            filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
  4.  
  5. @app.route('/', methods=['GET', 'POST'])
  6. def upload_file():
  7.     if request.method == 'POST':
  8.         # check if the post request has the file part
  9.         if 'file' not in request.files:
  10.             flash('No file part')
  11.             return redirect(request.url)
  12.         file = request.files['file']
  13.         # if user does not select file, browser also
  14.         # submit an empty part without filename
  15.         if file.filename == '':
  16.             flash('No selected file')
  17.             return redirect(request.url)
  18.         if file and allowed_file(file.filename):
  19.             filename = secure_filename(file.filename)
  20.             file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
  21.             return redirect(url_for('uploaded_file',
  22.                                     filename=filename))
  23.     return '''
  24.     <!doctype html>
  25.     <title>Upload new File</title>
  26.     <h1>Upload new File</h1>
  27.     <form method=post enctype=multipart/form-data>
  28.       <input type=file name=file>
  29.       <input type=submit value=Upload>
  30.     </form>
  31.     '''
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top