CGI Exemplos
Enviado: 24 Fev 2014 09:10
Ola!
Peguei esses exemplos no grupo de usuários.
Por Lorenzo Fiorini.
Agora eu não sei como, não testei mas os arquivos compilado com -cgi fica com a extensão .cgi ?
Porque eu uso com -hrb e fica .hrb
Saudações,
Itamar M. Lins Jr.
Peguei esses exemplos no grupo de usuários.
Por Lorenzo Fiorini.
Código: Selecionar todos
file_upload.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>File Upload</title>
</head>
<body>
<form action="/cgi-bin/upload.cgi" method="post"
enctype="multipart/form-data">
<p>Photo to Upload: <input type="file" name="photo" /></p>
<p>Your Email Address: <input type="text" name="email_address" /></p>
<p><input type="submit" name="Submit" value="Submit Form" /></p>
</form>
</body>
</html>
upload.prg:
function main()
local oCgi := TipCgi():new()
local hForm
oCgi:Header( "Content-Type: text/html; charset=windows-1252" )
oCgi:write( "<html><head><title>Upload</title></head><body>" )
hForm := getformdata( oCgi )
oCgi:write( hForm[ "photo" ][ "filename" ] )
oCgi:write( "</body></html>" )
return oCgi:flush()
function getformdata( oCgi )
local aData := hb_atokens( oCgi:HTTP_RAW_POST_DATA, chr(13)+chr(10) )
local hForm := {=>}
local cTmp
local aTmp
local aRows := {}
local aField := {}
local cName
local cFile
if !empty( aData )
for each cTmp in aData
if left( cTmp, 2 ) == "--"
if !empty( aField )
aadd( aRows, aField )
aField := {}
endif
else
aadd( aField, cTmp )
endif
endfor
endif
if !empty( aRows )
for each aField in aRows
aTmp := hb_atokens( aField[ 1 ], ";" )
if aTmp[ 1 ] == "Content-Disposition: form-data"
cName := strtran( hb_atokens( aTmp[ 2 ], "=" )[ 2 ], '"', '' )
if len( aTmp ) > 2
cFile := strtran( hb_atokens( aTmp[ 3 ], "=" )[ 2 ], '"', '' )
hForm[ cName ] := { "type" => "file", "filename" => cFile, "mime" => alltrim( hb_atokens( aField[ 2 ], ":" )[ 2 ] ), "data" => aField[ 4 ] }
else
hForm[ cName ] := { "type" => "field", "data" => aField[ 3 ] }
endif
endif
endfor
endif
return hForm
Porque eu uso com -hrb e fica .hrb
Saudações,
Itamar M. Lins Jr.