[REBOL] Re: arghh!@#$ => HELP please with http upload
From: andreas:bolka:gmx at: 1-Sep-2002 18:24
Sunday, September 1, 2002, 3:52:33 AM, Jason wrote:
> arghh!@#$ =>> HELP..
> Please, does anyone have a tested, working example of http upload
> script in REBOL with its HTML form?
For a very basic example, use the following two things:
- one cgi handling the HTTP POST
- a HTML containing the form
put the cgi into the cgi directory of your webserver (cgi-bin) and
modify the first line to properly reference your rebol.exe.
put the html into the documents directory of your webserver (htdocs)
and eventually modify the action="" to properly target the cgi.
here we go, the html first [no proper (X)HTML, i hope you'll forgive
:)]
--- snip - echo-post.html ---
<form
method='POST'
action='/cgi-bin/echo-post.r'
enctype='multipart/form-data'>
File1: <input name='file1' type='file' /> <br />
File2: <input name='file2' type='file' /> <br />
<input type='submit'>
</form>
--- snap ---
and now the (very basic) cgi:
--- snip - echo-post.r ---
#!c:\utils\rebol252.exe -cs
REBOL []
decode-multipart-form-data: func [
p-content-type p-post-data
/local list ct pd bd delim-beg delim-end mime-part
] [
list: copy []
if not found? find p-content-type "multipart/form-data"
[ return list ]
ct: copy p-content-type
pd: copy p-post-data
bd: join "--" copy find/tail ct "boundary="
delim-beg: join crlf crlf
delim-end: rejoin [ crlf bd ]
mime-part: [
( ct-dispo: content: none ct-type: "text/plain" )
thru bd
thru "content-disposition: " copy ct-dispo to crlf
opt [ thru "content-type: " copy ct-type to crlf ]
thru delim-beg copy content to delim-end
( handle-mime-part ct-dispo ct-type content )
]
handle-mime-part: func [
p-ct-dispo p-ct-type p-content
/local fieldname
] [
p-ct-dispo: parse p-ct-dispo {;="}
fieldname: select p-ct-dispo "name"
append list to-set-word fieldname
either found? find p-ct-type "text/plain" [
append list content
] [
append list make object! [
filename: select p-ct-dispo "filename"
type: copy p-ct-type
content: either none? p-content
[ none ]
[ copy p-content ]
]
]
]
use [ ct-dispo ct-type content ] [
parse/all pd [ some mime-part ]
]
list
]
len: load any [ system/options/cgi/content-length "0"]
post-data: make string! (len + 10)
while [len > 0]
[ len: len - read-io system/ports/input post-data len ]
tmp-post:
decode-multipart-form-data
system/options/cgi/content-type
post-data
print "Content-type: text/plain^/"
print mold tmp-post
--- snap ---
I hope that helps :)
--
Best regards,
Andreas mailto:[andreas--bolka--gmx--net]