[Tutor] uploading files with a form (long)

Kirk Bailey idiot1 at netzero.net
Mon Aug 25 21:52:56 EDT 2003


ok, back to the uploader issue, last task in the wiki.
http://www.tinylist.org/testform.html
the things sourcecode looks like this:
<HTML><HEAD>
<STYLE TYPE="text/css">
<!--  A { text-decoration: none; }  A:visited, A:hover, A:active 
text-decoration:none; } // -->
</STYLE>
<TITLE>Testing form for devlopment of the upload script</TITLE>
</HEAD>
<BODY TEXT="#000000"  BGCOLOR="#FFFFFF"  LINK="#0000FF" ALINK="FF0000" 
VLINK="0000FF"><blockquote
 >
<center><h2>Test form for uploading files<br>
to the images directory of this site.</h2>
<P>
<FORM ENCTYPE="multipart/form-data" 
ACTION="http://www.tinylist.org/cgi-bin/upload.py" METHOD=POS
T >

Send this file: <INPUT NAME="userfile" TYPE="file">

<INPUT TYPE="submit" VALUE="Send File">

</FORM>
</center>

<P>
<br>
ODD#8/14/03/kdb/testform.html
<P>
Peace.
<p>
</BODY>
</HTML>

The script of the moment looks like this:
#!/usr/local/bin/python
#
import os, cgi, sys                               # swallow the batteries...
#
footer='<P><br></body></html>'                    # define footer for later use.
form = cgi.FieldStorage()                         # extract data to a dictionary
# filename=form['userfile'].value
# filedata=form.getvalue('userfile','')
print 'Content-type:text/html\n'                  # warn apache what's coming...
print '<html><head>'                              # open the webpage up,
print "<title>Upload results</title></head>"      # name it,
print '<body bgcolor="FFFFFF" links="0000FF"><P>' # set up the bage body,
print '<center><h2>RESULTS</h2></center><P>'      #
print 'form=',form,'<P>That\'s the entire thing recovered from the cgi \ 
object.<P>',footer
print form.has_keys
sys.exit()



This is what appears on the page it is outputting:        the file's name
                                                           VVVVVVVVVVVVVVVVVVV
form= FieldStorage(None, None, [FieldStorage('userfile', 'wikinehesalogo3.png', 
'\211PNG\015\012\032\012\000\000\000\015IHDR\000\000\001;\000\000\000.\010\003\000\000\000`nNi\000\000\003\000PLTE\002\002\002\376\306\003\344}\003\265d\002\220Q\002n:\002\\1\002L)\002\376\326\002:\036\002\350\240\0024\035\002\376\342\003\276\222\002(\030\003\375\272\002\376\352\002\266w\002\234x\032"\022\002\362\266\002\312v\005\222`\004\034\021\002z^\012\376\365\002\350\247\005\343\212\004\375\212\003pJ\005\026\016\002\306\205\002\234`\003hK\002\373\362-\302\272&\306\3062\356\241\002\237r\002\356\250\005]?\003\210M\002\345\230\003\022\014\002\356\261\002\306\306.\270\207\004\376\372\002\364\331/\321q\002V?\003\322\203\002\366\3542\276\252.\312\225\004\376\376"\233f\002\245Y\002D2\003\362\300+\376\322\003{Z\006J7\006\264j\002\361\343.\375\220\002\016\011\002\363\315\'\323\215\003\365\217\003\264\200\005\362\237\002\310p\002xJ\003\332\242\012\364\332%\246i\002\352\230\004?+\004\323\224\004\362\250\002\242\232&\376\376\031\201F\002\376\276\003\225n\002\372\204\002\211R\002\33
3{\002{V\005d@\003\253z\'\346\2660,\037\005\375\226\002L0\0034"\004\342\222\002\332\322.\233R\002\361\344#\012\006\002\365\363"\376\316\003\326\236\002\376\332\003\220c\032\254a\002h9\002\366\236\002\365\3202\370\301\037\326v\002\375\256\002\312\216\002\276j\002\274~(\357\306\036\302\201\002\375\246\002T0\002\223W\002zv\036\314\230*\376\376\016\247{\036\\8\002\302w\002zE\002\356\215\002eF\003\221g\004o>\002\336\214\002\253r\004zP\004\272v 
\363\333\036\376\376\002\232f\036\375\252\002nE\004\362\266*@%\002\342\222*\362\262\002pR\004\370\354"\331\204\002\347\206\003\362\342\036\372\322&\245x\002\311|\003\333\224\002\360\230\002\211a\033\246k\036\254~\004\352\2362\372\312\032\375\242\002\342\252*\256i\003\361\313.\344\230 
\376\302\003\264q\002\245a\002\372\272"\274\200\003F+\005\275q\002\336\246\002\376\312\003]F\003\322\236.fO\026\314\212\002\327\267+\201_\005\306\234"\372\226\032\356\246*\356\326\036\306f\002\362\232*\306~"\256r"\234l\006\301\216\003\352\214\002\322\232"\211Y\032\366\362\032\035\026\004b8\002\351\222\002\373\373-R8\005\352\262\002\276x\002\211b\006uC\002\202J\002\376\262\002.\032\002\370\322\032\202Q\002\270x\022\376\356\003\356\177\002FB\026\334\232\002\376\336\002\376\266\002\375\232\002\316\216&\274\224\033"\027\003j@\004\336\205\002\210Y\003\234Y\002\236b\036\376\236\002\317|\003\241r\027\245n\002\374\266\026\366\231\002\366\346\032\372\246\036\254x\005\374\364\026\222o\032\356\222"\376\346\003\356\262&\332\215\005\006\006\002\345\216\002\366\272\0325&\005\302~"\276e\002^B\032\356\316\036\314\204\003\323\251 
\301\206\002\276\216"\326}\004F&\002:$\003\000\000\000n\224\221\217\000\000\001\000tRNS\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\3
77\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\000S\367\007%\000\000\021\352IDATx\332\355\233\177\\\033\347y\300\357\014\001Y0N\224\000\225!\004\267\263\021"C\261\311\022pd\260\010\2068\301\210\215\213\177\320\202\304\250\202\025 
\366\341\005\311["cl\254\204\036c!\270\345G\352\371\232T0\254\310\263K\232d\235\315\3621\012\005\373\250\203g\235\032\004D\304\361\3062f\023\352N\311\000\365$\235\356N\322I8i\222\356\363\231\337\277\320\373>\357\373<\317\367}\336\347}\337\273\003p\336-_\266\000w\021\334ew\227\335]v\377\037\331=\264\355A\377v\262\312\277\356\241\227\036\373\032\014yh\333\263\217r\325?MZ\360\330\377qv\217<\337J\025\351g\236\232\367\036i\245\313\376\017()W\335\363\255\022\365\233\214\323\017\276\3161\356\243\037\254\242x\033\013\210W\221\3403?!\332\250\3507\357\330\243G\337\374\206\331\375%\203I\310\373\325\005\027\222VV\021\032.\014\272qR\277\347\357\335\367\',\347x\017\237e\217\371\0369\232`\337\231\340J\037q\253\023\334{\324\207\034I\310\360\204\217\034=\235\002\350\344\231\304\325\235y\317eNH\315_\003\273\377dq\262\274\361\324\372\016\347\237\262\321I\300\223[\000\227\244\220\372\375\300S\337\356z\201\366M\260\257\243\342\026m\277\247\362\336\216\374\240\344\250Q\341\247r/\272~3z\324\320\02
3\231[\031\301\237\012\275\372\177\2655\003X-3{c\364\201\340\232\277\026v 
o\202\346\264n\375-\322\316\317xj!\355\223i\020\000\334\266w=\374\206\224\374\235Izr\353\223?\363\366\350\312\000(\317\336\363F\212zkP_\275"\017\224xz}k\335\313&\357\264\221\341\\\310\204\360\'\017\357\273W\340\252\317\004\000`\025vt\360\252\007\001\340\033ew\364\251\215\231\367ztCg\334\206\002%\353\307\012\015\024\272\016\257\355\025\233;\216^\200\007=\022\363\236\326\243\000\355\031\275\306Z\273\202\372\272_\342\026x\231\3515\262Y\324Q(u\257Y\210dw\262\203\226\335\274Y\2645S*8\003\254\312n\376\0164\177]\371nqqK\363F\302bQ\277L\201!K\305\226\365\'\341y\013\017\246\350\270E\027;\006;\274\002[\316\344\322\302\256\306O\005^\007\326\005w\266\260!sL\351\323\315\011\334J,\321\357\223F\317\253\015\017<\234y\362\344 
-\234QQ"\032\024\261e\203\024\010\264x4\277<\011|c\360\274j2&K\316t\245A\3605\021mh\306\342\34619h\202\327u\260m\337\330%\0028\013\031\275\231\027\370\356\345g*\011\356l\356\242_/\227\021)\213\2337>`\252\251\001\011\376\205\314\223]\014\274\213\271\353\007\225w\300\356\333\347\273.\020d\222Qw\254\036\243_\375\031\245b\213h\260\201\200\236\330\313\260\333\254\337x\015\006!\376Q\025\313\240k\373\006\203\261s\226\3446\017\016@\226\232\256P\316\002\201\354\310\\\260\367x\032h\200`\003\261\256\341\363\302\256\363\264t\307\330\371\305;`\347T\346\256\037;\007\326\310\027\377(\354rE[\013\371i\015[Sh\355[\273\006\326Ap\232\374\251\012\306\240o\031\340\221`\350\\\364\316\2145\300\320\371\220\316r\261\3538z\222o\300K\021\002\202\326\3113O\316\321\360\006c\013s\201;\341\241l\336:\227f\370\343\260\2738\322\334q^^z\3558\263\336\316\312\371\204\024\304\367\0154\253h\203>U\253\031\267\003!,n=\336@\340c\241\275\015\350\345\2548z\2741\215\214\271\264R\310\000\245\311\007\346\346\316\257\367\2
64d\256+=\3165\332\203\317>\347;\350\305\275\331\205\353\014\362\025\226\354\203\317\375\035\267\001\317\276\316y\205\241\307\374)G\333c\217~\032\374N6R\33616\320s\355\363\216\024\257\362\243\020\\\243\006Q\276\347\033`\026;\352\3242\301\223\373\300\373\267\277\370\321\3335=c%\336\232\271\314\202R\010\341\247\225\2420L\244\3113\013\347\346\365\337\241\256\007/EK\204R9G\323\363\022A\315\023A\330\225\210\332\366^\227\363\033\262\225^SOIy\321\363 
\272\241\247\260Y\231\2221\351\252\372\276P2\301r\345\257^\361\034\235\033\3133<\203\234\275\277g\203\001N\360\262\373s\357\275D\215\236\317\315\360j\372\356\323\356s\212\264\241\231\276+\334\177\356\032\002\343|\262l\340\243\244\306\201\330\271\330W]\015\247\242\005\204\037;\372\016$\261\230\220\217\350\352\317\035|\034\344S\033\231\363i\317\224\325\340=\203>\344\350c\324\004\017\346\263\032\250A\205\255\317?\337:\001\237\323s\364h\235\227\302\245\037q?\013\020\225\3377\326X\304\037\020M\252R*\334\267\010\201P(0\240\374\242\202\354\021e\305\351E\317\005$\237v\345\025/\031D\237A\215\263U\316G\0140\235\357(\011\001|\375"\355\375\217\274\306\300\323\211\264\366\302\236\0158Hhz\012\316\235\223\213\021\004\355i\034\030\220\313=\012\371>\350\276\3439\001\337\357\020JZ%5\245\005\317x\033\344=E\220\011\235\216\001\362\311\330{\232\002d\3320:\235\353O\310P(v\033\305\277\177\257\337\201\335bR\273\346\244t\314s\343\241\033\346\015\256\343\227\204G\210\007\3068\331)D\315W\346\344U\347\
022\024\213+\345\025dP\271\217\253D)_L\366\020\215\254?\012\270\357O4\272hz>\346\350\033\323\253\342"\004\204\347\022)\241\017\334\355h"+rNI\274\304\033/2D\336\027o 
\014\210#;a\254\270\261`\247\206@{\012\012\304\370)\267\302l6;7:O\332\230DZ\205hc\266\367(\335#.%L\245\305\271\223\025\345\300\333\364=\274`,w\022\360!\204\273;\227\013Z\325E\261\011"O\003u\253*\212q\337\012\012\246+(}\317\272j\345\356\016m\010\011\003o\310./\341bW\241k\326g\367`\033\032\247\233\327\'|\0048]N\012\360\233\216\202*qA\337\264>\241\340\023\347\266\326\326Q/\207\027\010\220\242\207*i\347\236q\261\003\035\256\375&\337U\365$\331<\355\2631\3400\317s\331\203\024,$s\342"\034\272\277y2e\262\244\355\374\300N\015\256\331PT\012{n\013\012\026\273\'\031t\000\240\'ZM\003{u\213\236&q\257\006\002\221QQ\242jR/$#\310\245f\002>\256K\241\225\270\321Q\031 
.;\272\0259\336\241\253p\267x,*\0108\001H\350X\001&\365d\260\342\261\367)\363\001\256\347w#\345m\323\261-U7c\263S\033\3617\177\340\262\362\346}\242+\307\013\304U\216\321\276F\214\36763\024)^\034\353\320H]s\253g\224\035%\331\031\014=\372\250D%\271r\316\272: 
\276\346d_\037\025\303\244\255\322Tv\032+\254*B\261r\352>\243o\254\252Gq\234\000\335\354$\371,9\267\217Wg\255\221\266\004\007\252\351V\262\330\211Iv\006\354\346hq#&\365l\206J\377\303\234Rt\345\372NM\201\017\273\367\315\275\365m\264`\206.\265\240\027\205j\242I#x\323\214\334[\026\001\351\177Q\024%vJm\261\024\347{\033\315;1\334`V0\276+\333\372z[F\350\316\373\243]Y\255/\005p\273\237\033\255\216\266\264Qm\030\246!j\014\005\272\024?v\027Y\277\3460\324 
Eu at 0v[\312\313\257\364e\3554\223\231\203\'Pw{=i\213mYp%\023\251\251\317\227\202hwv\026\212t\263\256\035\317T\365b\004\214\366\366.h`\317\355\034\036\367\277R)\333\246\373\314H\213/\273\252\336^\226\241*E\366\354\0029\220\311\004%i\031\271\217k,\023\255\022q\271B\267\327\361\334\017^\221X\240b\246\261\312|\003\205Z\230@\211Q\350\257/d\215\320\002R\365\274\2445:V\247h\033\253\372\237m\222\011\236\206\3165\243\243\243\335-\275\216C"\205nG[\014\313^\026\307\027AP\312\303N\007e\247$3^\252ca\301\214!\004\266\203q$\301A\302\303\260\336T?\014\242\342\276\254\0337\212Y\333\350\253d_\202\260\367\336\250\307\245\356\247*\026s\300s\201\230\351\376Q\263\306\241\364a\267\340\303\016\000\264\331\335\275v2\036\314\261\355\214\0349}\363B\336\302\016\235-\025#s\241!\201\035\322I\013\365\344<&\322U%\227\023F{\263t\336\366\337\200&\236@\010\367\331tmF\\B\356\3206\246\263M\257\277<]|x\324\230\235\332\347\250:\037\343s\370\247\376|\335\242\266\360\314>\023\356{\323\321\016\333\246\215\013\346\005
\363\320,3t\306\351\364\303-SI\013\263\251\371~\354~g\354N\302\260\327RXq\227\264\035\303q\353BK\213Y\003\363,<\020\311\262\215\337\362\273\026\024\033\227z\261\245(\037vI\333\255\276\331F1\323=5\225\2244\325\307b\207\222\233t4a\\\341\274M\'\015Y\021|\211Yv\242\324\274%\373B\233\267\375g8\004\252y\326\351\030\216\316Q\212\222\250\250\222\035\306\244\316\254\251\244\241\226\342\323,>\000\360\302\337>\367\366KO\012\347\243-`R\010v%:\333\216~\322\346\251\245if\350\230\310\246\342\245N\322\013\255\377\352\323ww\336 at 5\207\331q\227d&=\250\234\355\2339\246\033\336\2357K\216T\254[\031\217Id\3539\334\335bE[|\343n\350\206\335\317\243\305\246\276\331\316\251\205>F\356#\253]\003\031n\224s?\211X0[Q")\206\256\030\311\033m\301\354\207\274?o\332Q\002\204;\3339;G\305\220IP\265\222j\266\333\255\275\235\306i\005m\356\317\377\235\274\037\010\310\274k\2511\201\370\322JpvN\335\260\355\2201kj\312\310\354\216\252\012\205-!>\253s\351P\206?\273w;\223*5\230\3217\356\3548~\303\330\344\316r\371\332\324\3
56\251\331\231rE{\373$K\311R\347\220\035\235\362\215\273!+\352\357R\234\355\265\331\254\331\376IZ.a\212T\2471\306q\263\033\332nE\240Nf\275\335\027\277t\004\303hv\357\2378bG\3543\334\217\200&=\335b\372\355\010j\2352\036\262)\345\023w\277\254\304\300\200\024=\336Tk4\24624\364F\343\354\221\312\274\024nv\333\255\030\202\3073\322{\263\246nh\254\351\336\337\251\306\303K\333\267\247\007y|Fmh\2233V\034\353\314K\327E\256\270\321M\220\027?aM\277;si\323\215S\306\366\020\354\242"\206\217\315\030\367\204\015\263\206^Q\350.\025/\305\317D\005<\203\374a\262\314\216\323\201\340\256\331.\303\020\315\211+L\332"\341\205\355>\026\241U0J\266WZ5\310\032\0373\254V\224\027\220\241\201\213u\207\302f\230\323\343H\377L\177\336lm\024\367\303CrP\202\330\303\260{\227\234"\024\273\354\225h;Dv>\234\036\354\311#\365\367rX\245}\350\265K\247\243\334\013e~\236\204gir\267\334\322\3566\236\230\325\205`\347\324\352lW\362\016\024G\261F\036\217\324\326\205\037<\330\024\020v\316\237T\222I\004{\234\225\004~B\246$B\263\
246\216\226M\034\256\235Z\012\013\267\325\015k\351n.\031|\312\'\355\222\007\254\3508\300\'E\273\257\016\021\273/\2632BSSYz\377\214N\305\345\375\213\230\006\205\210Y\206\364\207\'dv\324\233\357\000g\311\245\266\246\360\332C\343\034\350\376\351\324\217\317z\343d\367\236\312\344\376\210\304[\031J\247\363\327j\213@"\\\242n;3yk*\217\204\253B\260k\'\003/\274\366\230\217Y\221Z\335\245\360C\313\201\217\276\177i\'\227Ie\030\213]\222\035C\021Y-+#\217\327\325\306?\236\267\373\222\355\330\210\267\233F\203\342\330\246\010\366h\010\002\253#}\316N\324\036\277<\314z\340\257\320j\265\307\302\303\265qq\3431^\321\237\235\360D\364oI\305\204=\207\311\037\037&\313\254\232#\341\264\321\021\012\355pz\355\245\250\304\270\250|\252\363\357\260x\327\315\276&Z\310s\317d\306\332\341\360\003k\016\332\\\355\267\200\263&\320\244\236\000)_\332Nl\257\304d\324*\340fW\241\215\250+\013_\361\341\244\214\324\016_.\313\010d\367\013\024\301\021\231w\201\273kH,x\345kZ\206]~{\331\301\003\233j\323/]*\243\226\355\337\223
WUH\263\207\012(w\325?C\260\311R\3463:\275c\260\264^\\;\036\023\025\021\036~\251\256i\3465\327#\220\357\3757\210\334\366\014\373_\010B@\225\375L2\177\221\\\304\250\254\226N(\025k\307\307W\206\253/\327\331.\327&\264\223\002\277\331\017\332g\\\235\241\032\201\351\204\353P\235\330\037\266\347\304\236p\212\377\017\255\225v\304p\225\032\361\267(\246\301da\021\211\301\3319\333\265\332\210{T\276\234"##\352"\003\227,\031-\004\271 at k\357a(hH\232\2325\325\021\2545\221\261\266\256l\246:\274\254\351r\370\016w\257\217!\010B\222o\037\213aF# 
\030\004\253\343\310\333%\020\362\245P\212+"\342\216\345\344\324\276s\265\022\205MR)\274)\316\323F\256\000\002\271\032\316\254\331$\253U\203\255\231\241\023\240*\203\364\352\326JuNN\330\201d;n\250\221\326\240\351n\3115v\036/\331\235y\226d\262\3440o\276\212\011\317\011;\270)\247=#\245\235\004\366)\244\251\334\365\370\214\207\035\300\315\256by\355\332\014?Nk\333Wb8\320a\250\006K\316\211\244f\326\365\014\370?pD#\313Y\346\330\011S\326F\336\323T\326\377\241\323\371\217\006\002\267\277\0231\356\231\037\327\367\017\377\000\021\004\216=\276\254\362\033\237\343\245\020\225\321s\336Y#\263#\020\010B\341T\333/fyyy%*&n|\370\240\371\327R\353\2462m\234\312g\177\011x\2531\036\247\362\347\224\022\223\002\004\262KN\336\265\251\214\225\267\225\316\2171\331\256\2348 
h\311_\276\375\275\375\204}W\355ZV\235\363\2575\262\344591\034o\022\203\261#\'\252\372\300.\253]F\347\314\331]W\017T\307\261\245\343\257n\252^\366{\207N\225\310\333WeV\373U\272%\261}\271n\327\201d8\232\007UVs\331\255Z\236\331\025\311\2617\007\260\313\010|\215\345Tq\240{7\247\314w<\300v\273\272N\005\254R""\374\316\030\316\323e\367\254\345\320\311\375F-\310\373\315\262\364\210|\337\232\352K\313\301\016"\001\311\300c\364\261]\357D\000wZ\202|\367\311\341\006\247kQ\300WS\234\234oz\203\331\302\355H`\260\253B\234\342\374\033\356\320\260/\307\316\011\254\262\242B\250\370\203\3309C\316c\010-N\340\013\260s~q\333\203}o\034*\000B}\037\021\372\310~\307|9U\204R\032d[^](T}h\333\203\177\253\035<\000B~[\0028\235wjX\250\211\347\264&\244\326 
\2732\347\240A\202<\010S\347\027f\347\014\306)\344\267%\301\316\025\201i 
\244\215\234\326\254\372U\306j\033\313j\235\235\301\362\006\327\024\177\205\377#\300\265\314\356\244\027\360\207)\015\302y\265\212\220\026\006\013\374\325\377G\340n\371r\337A\335-_\270\374\036\177\034\036#D\324\245\376\000\000\000\000IEND\256B`\202')])

That's the entire thing recovered from the cgi object.

ok, I have tried, and failed. Someone give me a clue please. IN fact, give me 
SEVERAL clues. This may well be a 'can't see the forest for the trees' issue.
-- 

-- 

end

Cheers!
         Kirk D Bailey

  +                              think                                +
   http://www.howlermonkey.net  +-----+        http://www.tinylist.org
   http://www.listville.net     | BOX |  http://www.sacredelectron.org
   Thou art free"-ERIS          +-----+     'Got a light?'-Promethieus
  +                              think                                +

Fnord.





More information about the Tutor mailing list