[問題] python 檔案上傳
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://www.ptt.cc/bbs/Python/M.1421809898.A.A24.html
※ 編輯: gn00618777 (118.163.147.121), 01/21/2015 11:54:59
→
01/21 12:42, , 1F
01/21 12:42, 1F
→
01/21 13:20, , 2F
01/21 13:20, 2F
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):
問題
0
2