Alex,

I am still assembling a library to be distributed but the piece that
decodes uploads is this one:

check the source for it fills a global called gDataA with data, for
example the files goes into: gDataA["FILES"]

Cheers
andre

--> File Upload Related (MIME Decoder)

--on decodeUpload
if  "multipart/form-data" is in toLower($_SERVER["CONTENT_TYPE"]) then
        ## Mime enclosure!
        read from stdin for $_SERVER["CONTENT_LENGTH"] chars
        put it into gDataA["SERVER"]["STDIN"]
        ## Get boundary
        local tMIMEBoundary
        set the itemdel to ";"
        put item 2 of $_SERVER["CONTENT_TYPE"] into tMIMEBoundary
        if "boundary" is in tMIMEBoundary then
                set the itemdel to "="
                put item 2 of tMIMEBoundary into tMIMEBoundary
                ## We got the boundary let us split the files
                local p = 0
                repeat with x = 1 to the number of lines in 
gDataA["SERVER"]["STDIN"]
                        put line x of gDataA["SERVER"]["STDIN"] into tLine
                        if tMIMEBoundary is in tLine then                       
        
                                ## We got a new part.
                                add 1 to p
                                put lineoffset(crlf & crlf, 
gDataA["SERVER"]["STDIN"], x) into tHeadersEnd
                                put line x+1 to x+tHeadersEnd of 
gDataA["SERVER"]["STDIN"] into tHeaders
                                repeat for each line tHeader in tHeaders
                                        set the itemdel to ":"
                                        put item 1 of tHeader into tHeaderName
                                        put item 2 of tHeader into tHeaderValue
                                        trim tHeaderValue
                                        trim tHeaderName
                                        if ";" is in tHeaderValue then
                                                # We got attibutes.
                                                set the itemdel to ";"
                                                put item 1 of tHeaderValue into 
gDataA["FILES"][p][tHeaderName]
                                                put item 2 to -1 of 
tHeaderValue into tHeaderAttributes
                                                replace "; " with "&" in 
tHeaderAttributes
                                                replace quote with empty in 
tHeaderAttributes
                                                trim tHeaderAttributes
                                                split tHeaderAttributes by "&" 
and "="
                                                repeat for each key tKey in 
tHeaderAttributes
                                                        put 
tHeaderAttributes[tKey] into gDataA["FILES"][p][tKey]
                                                end repeat
                                        else
                                                put tHeaderValue into 
gDataA["FILES"][p][tHeaderName]
                                        end if
                                end repeat
                                put x+tHeadersEnd into x
                                
                        else
                                put tLine after gDataA["FILES"][p]["Content"]
                        end if
                end repeat
end if


-- 
http://www.andregarzia.com All We Do Is Code.
_______________________________________________
use-revolution mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to