จากฟอร์ม upload.py
โค้ด: เลือกทั้งหมด
get_img = image1.png
โค้ด: เลือกทั้งหมด
show = get_img
Moderator: mindphp, ผู้ดูแลกระดาน
โค้ด: เลือกทั้งหมด
get_img = image1.png
โค้ด: เลือกทั้งหมด
show = get_img
โค้ด: เลือกทั้งหมด
data = 'name='+image_filename
request = Request.from_values(query_string='foo=bar&blah=blafasel',content_length = len(data), input_stream = StringIO(data),
content_type = 'http://localhost:5002/',method = 'POST')
โค้ด: เลือกทั้งหมด
UPLOAD_FOLDER = '/home/com003/PycharmProjects/test_project/work01/'
def view_file(req, file_img=None):
print UPLOAD_FOLDER
#print req.method
if request.method == 'POST':
file_img = request.form['name']
print 'user = '+file_img
return file_img
file = UPLOAD_FOLDER +file_img
print 'file = '+file
f = open(file,'r')
return BaseResponse(wrap_file(req.environ, f), mimetype='image/x-png',
direct_passthrough=True) #wrap_file(req.environ, f) ฟังก์ชันตัวมันเองไว้จัดการไฟล์ที่ upload เข้ามา โดยรับ paramiter จาก f = req.files['uploaded_file']
def application(environ, start_response):
req = BaseRequest(environ)
#if req.method == 'POST':
resp = view_file(req)
return resp(environ, start_response)
if __name__ == '__main__':
run_simple('localhost', 5002, application, use_debugger=True)
สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 1