作者gn00618777 (非常念旧)
看板Python
标题[问题] python 档案上传
时间Wed Jan 21 11:11:35 2015
http://ppt.cc/uuqN
我有一个上传页面.html,内容有
<html>
<form action=upload_file method="post">
<input type="file" name="file">
<input type="submit" value="Send files" />
<form>
</html>
-------------------------------------------------------------------------
主程式
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
---> 这个 function 是用来判定传进去的 filename 的附档名是不是符合
ALLOWED_EXTENSION里的元素,传回 True or False
@app.route('/', methods=['GET', 'POST'])-->这个路径在客户端是显示甚麽..???
def upload_file():
if request.method == 'POST':
file = request.files['file']
if file and allowed_file(file.filename): --> filename从哪里传进去阿??
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return redirect(url_for('uploaded_file',
filename=filename))
return '''
<!doctype html>
<title>Upload new File</title>
<h1>Upload new File</h1>
<form action="" method=post enctype=multipart/form-data>
<p><input type=file name=file>
<input type=submit value=Upload>
</form>
'''
谢谢。
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 60.251.223.31
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1421809898.A.A24.html
※ 编辑: gn00618777 (118.163.147.121), 01/21/2015 11:54:59
1F:→ bibo9901: 建议还是先会写 HTML 再来 01/21 12:42
2F:→ gn00618777: OK,用 html 简单多了,谢谢。 01/21 13:20