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

Examples needed...

 [1/2] from: jean::holzammer::faedv-n::bayern::de at: 18-May-2001 11:33


Hi, I try to gain some more experience with web applications and could need some sample code. Maybe some of you have already done one or more of the following. 1. File Upload via a html form: Needed: - a html page using a form with input type="file" - a cgi script saving the binary(!) file to the filesystem of the server machine 2. MySQL:// inserting of a binary file into a BLOB column ; i always get corrupted data, probably a problem with reading/loading of file and conversion Needed: - a script inserting a (local) binary file into a BLOB column - another one selecting this column and saving the file back to the filesystem Ciao, Jean

 [2/2] from: ryan:christiansen:intellisol at: 18-May-2001 16:45


To upload a file to your server using an HTML form, use the following two functions in your receiving CGI script. The usage in your script is as follows... cgi-input: retrieve-user-data That's it. Then you will have the contents of a POST or GET operation in a REBOL object! If POST input was sent using an HTML form using enctype=multipart/form-data, the object will include the variables filename (the name of the uploaded file), file-mime-type (the mime type of the uploaded file) and file (the file itself in binary.) -Ryan decode-multipart: make object! [ form-data: func [ ][ post-data: make string! 100000 while [0 < read-io system/ports/input post-data 100000] [] post-data: make binary! post-data parse/all post-data [to "----" copy text thru "^/" (boundary: copy text)] cd-block: [] parse/all post-data [ any [thru boundary copy text [to boundary | to end] (text: make binary! text append cd-block text)]] cd-input: [] foreach cd cd-block [ either find cd "filename" [ parse/all cd [thru {name="} copy text to {"} (append cd-input text)] parse/all cd [thru {filename="} copy text to {"} (file-path-string: copy text)] file-path-block: parse/all file-path-string {\/"} filename: last file-path-block parse/all cd [thru {Content-Type: } copy text to {^M^/} (file-mime-type: copy text)] ; parse/all cd [thru {^M^/^M^/} copy text to {^M^/} (text: make binary! text append cd-input text)] parse/all cd [thru {^M^/^M^/} copy text [to boundary | to end] (text: make binary! text append cd-input text)] ][ parse/all cd [thru {name="} copy text to {"} (append cd-input text)] parse/all cd [thru {^M^/^M^/} copy text to {^M^/} (append cd-input text)] ] ] cd-input: head cd-input object-data: make object! [] for x 1 (length? cd-input) 2 [ variable: first cd-input cd-input: next cd-input value: first cd-input either binary? value [ make-object-data: reform [rejoin [{object-data: make object-data [} (variable) {: } (value) {]}]] ][ make-object-data: reform [rejoin [{object-data: make object-data [} (variable) {: ^{} (value) {^}]}]] ] do make-object-data cd-input: next cd-input ] make-object-data: reform [rejoin [{object-data: make object-data [filename: ^{} (filename) {^}]}]] do make-object-data make-object-data: reform [rejoin [{object-data: make object-data [file-mime-type: ^{} (file-mime-type) {^}]}]] do make-object-data object-data ] ] retrieve-user-data: func [][ either system/options/cgi/request-method = "POST" [ content-type: system/options/cgi/content-type content-type-elements: parse content-type none enctype: content-type-elements/1 either enctype = "multipart/form-data" [ decode-multipart/form-data ][ post-data: make string! 100000 while [0 < read-io system/ports/input post-data 100000] [] return make object! decode-cgi post-data ] ][ return make object! decode-cgi system/options/cgi/query-string ] ] "Holzammer, Jean" <[Jean--Holzammer--faedv-n]. To: [rebol-list--rebol--com] bayern.de> cc: Sent by: Subject: [REBOL] Examples needed... [rebol-bounce--rebol--com] 05/18/2001 04:33 AM Please respond to rebol-list Hi, I try to gain some more experience with web applications and could need some sample code. Maybe some of you have already done one or more of the following. 1. File Upload via a html form: Needed: - a html page using a form with input type="file" - a cgi script saving the binary(!) file to the filesystem of the server machine 2. MySQL:// inserting of a binary file into a BLOB column ; i always get corrupted data, probably a problem with reading/loading of file and conversion Needed: - a script inserting a (local) binary file into a BLOB column - another one selecting this column and saving the file back to the filesystem Ciao, Jean