#!/usr/bin/env python3
import cgi
import os
from http.cookies import*
import sqlite3
path= '/var/www/html/bb.db'
con=sqlite3.connect(path)
cur=con.cursor()
form=cgi.FieldStorage()
print("Content-Type:text/html\n\n")
print(
"""
<html>
<body>
<form enctype="multipart/form-data" method="get">
<select name="drop" >
<option>5star</option>
<option>Munch</option>
<option>cadbury</option>
<option>Kurkure</option>
</select>
<br>
<input type="file" name="preview" accept="image/*" >
<input type="submit" name="submit" value="submit">
</form>""")
a=form.getvalue('drop')
b=form.getvalue('preview')
if 'submit' in form and a!=None :
cur.execute("drop table images")
cur.execute("create table images(img blob)")
cur.execute("insert into table values(?)",(codecs.encode(form.getvalue('preview'))))
print("""
<p><img src=""")
cur.execute("select * from images")
data=cur.fetchall()
print(codecs.decode(i[0][0]))
print("""alt="hii" style="width:320px;height:320px;border:0;"></p>
</body>
</html>
""")
我正在尝试使用python cgi检索以html格式上传的图像... 但是这段代码没有用,....请帮我解决一下代码.. 提前致谢 ... 实际上我也使用了以上形式的enctype ......但是它没有用......