Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: enctype="multipart/form-data"

From: ljurado:bariloche:ar at: 29-Apr-2001 16:11

> I want to be able to submit image files using POST and to save those image > files from the POSTed input. I am taking steps in this direction, and so I > gave my form tags a new enctype attribute.
With this modified post.r script and form-upload.r I can upload binary files (jpg, etc) But this is today work , beware .... Luis Rodriguez Jurado. ================== #!c:/rebol.exe -cs REBOL [ TITLE: "form-upload" FILE: %form-upload.r DATE: 29-April-2000 ] print "Content-Type: text/html^/^/" print { <form METHOD=POST ACTION="post.r" enctype="multipart/form-data"> Enter a description of the file:: <input TYPE=text SIZE=50 NAME=text><br> Select the file: <input TYPE=file SIZE=15 NAME=myUpload><br><br><br> <input TYPE=submit VALUE="post.r"> </FORM></INPUT> } #!c:/rebol.exe -cs REBOL [ Title: "multipart POST" Date: 15-Sep-1999 Version: 1.2 File: %POST.r Author: "Andrew Grossman (modified by: Luis Rodriguez J - .29-April-2000)" Email: [grossdog--dartmouth--edu] Owner: "REBOL Technologies" Purpose: { To decode multipart encoded POST requests, including file uploads. } Usage: { Call this file in your CGI scriptand do decode-multi with a file argument of the directory where uploaded files will go and a logic argument to set whether files will be given the field they were uploaded as as a name. Files are saved and variables are decoded and set. } Notes: { Fixed problem recognizing EOF. Functionality is now rock solid. Function calls won't change, so this is certainly useable. See the comment in the decode-multi function if you need mime types. Tested with MSIE and Netscape for Mac. } category: ['web 'cgi 'utility] ] decode-multi: func [ file-dir [file!] {Directory in which to put uploaded files} save-as-field [logic!] {save files as field name or uploaded filename} /local str boundary done name file done2 content ][ if equal? system/options/cgi/request-method "POST" [ either not parse system/options/cgi/content-type ["multipart/form-data" skip thru {boundary=} skip some {-} copy boundary to end] str: make string! input do decode-cgi str][ str: make string! input done: false while [not done] [ name: make string! "" str: make string! input either equal? "" str [done: true] [ either parse/all str [skip thru {name="} copy name to {"} skip thru {filename="} copy file to {"} skip to end] [ str: make string! input if not equal? str "" [str: make string! input] comment {if you need mime put "parse/all str ["Content-Type:" skip copy mime to end]" into the preceding if block.} done2: false content: make string! "" while [not done2] [ content-length: to-integer system/options/cgi/content-length str: make string! content-length read-io system/ports/input str content-length either d: find/reverse tail str boundary [ e: find/reverse tail copy/part str (index? d) {^/} content: copy/part str (index? e) - 2 done2: true] [ append content str ] ] if not none? file either save-as-field [name: dehex name write/binary file-dir/:name content] [ file: dehex file write/binary file-dir/:file content ] ] ][ parse str [skip thru {name="} copy name to {"}] str: make string! input str: dehex make string! input set to-word name str str: make string! input ] ] ] ] ] ] decode-multi %. true