Форум сайта python.su
#!/usr/bin/python
# -*- coding: utf-8 -*
import cgi, sys, MySQLdb, os
if sys.platform == “win32”:
import msvcrt
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
form = cgi.FieldStorage()
if form.has_key(“id”):
id = form.value
else:
goto .end
conn = MySQLdb.connect(host=“localhost”, db=“artemvv”, user=“artemvv”, passwd=“elochka”)
conn.set_character_set('utf8')
cursor = conn.cursor(MySQLdb.cursors.DictCursor)
cursor.execute(“”“
SELECT SUBSTRING(name, CHAR_LENGTH(name) - 2, 3) as ext, name, file
FROM information
WHERE id = %s
”“”, (id))
row = cursor.fetchone()
sys.stdout.write('''Content-type: application/\“%s\”
Content-Disposition: attachment; filename=\“%s\”
%s''' % (row, row, row))
cursor.close()
label .end
Офлайн