python http上傳文件處理示例
<HTML><FORM ACTION='cgi-bin/action.py' METHOD='POST' enctype='multipart/form-data'> <input type='hidden' name='user' value='lola'> <input type='hidden' name='action' value='upload'> <BR><I>FILE:</I> <INPUT TYPE='FILE' NAME=upfile> <br> <input type='submit' value='Press'> to upload the file! </form>
</HTML>
File:action.py
!c:/Python25/python
import cgi import sys
def gen_html_header() : print 'Content-Type: text/html\n\n' print '<HTML>'
def gen_html_trailer() : print '</HTML>' gen_html_header() form = cgi.FieldStorage() try : file_contents = form['upfile'].value print file_contents except : print sys.exc_info()
gen_html_trailer()</pre>
本文由用戶 cgdf 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!