Clipper On Line • Ver Tópico - Salvar arquivos Upload HTML.

Salvar arquivos Upload HTML.

Aqui você poderá oferecer suas Contribuições, Dicas e Tutoriais (Texto ou Vídeo) que sejam de interesse de todos.

Moderador: Moderadores

 

Salvar arquivos Upload HTML.

Mensagempor Itamar M. Lins Jr. » 25 Set 2018 17:46

Ola!
Vamos supor quê, vc tem uma página na sua casa/escritório e quer deixar um site online, (usar aquele CPU velho esquecido)
Instale o Linux nele com apache e o harbour.

"MadarArquivo.html"

  <form action="/cgi-bin/PegarArquivo.prg" enctype="multipart/form-data" method="post">
    <p> Descrição do documento:<br>
    <input type="text" name="observacao" size="30"></p>
    <p> Informe o arquivo.<br>
    <input type="file" name="datafile" size="40"></p>
    <div><input type="submit" value="Enviar">
    </div>
  </form>


"PegarArquivo.prg"
#!/usr/local/bin/hbrun
#include "fileio.ch"
******************
Function Main(...)
******************
*
*
LOCAL cTemp:="", nRead, nLen
LOCAL cEOL := + hb_eol() + hb_eol()
LOCAL cArq, nPosKey, nInicio, nFim, hFileInput
LOCAL cInicio, cFim, xContent:="", xFile, cBuff, cOut

if "POST" $ Upper( hb_GetEnv( "REQUEST_METHOD" ) )
   nLen := val(hb_getenv("CONTENT_LENGTH"))
   cBuff := space(nLen)
endif

outstd( "Content-type: text/html" + cEOL )
Outstd( "<!DOCTYPE html>" + hb_eol() )
OutStd("<html><head>" + hb_eol() )
OutStd('<meta charset="UTF-8"/>' + hb_eol() )
OutStd('<pre>')
OutStd( "Tamanho: " + str(nLen) + hb_eol() )

Do while .T.

   nRead := FRead( hb_GetStdIn(), @cBuff, hb_BLen( cBuff ) )
   Do case
   case nRead == -1
       OutStd("Erro lendo stdin: " + hb_ntos( ferror()) + hb_eol() )
       exit
   case nRead == 0
       exit
   EndCase
   
  cOut := hb_BLeft( cBuff, nRead )   
  if hb_BLen( cOut ) > 0
     xContent += cOut
  endif
 
enddo

nPosKey := hb_at("filename",xContent)
nInicio := hb_At("=",xContent,nPosKey)+2
nFim    := hb_At('"', xContent, hb_At('"',xContent,nPosKey)+1 )
cArq    := SubStr(xContent,nInicio, (nFim - nInicio) )

//outstd( substr(xContent,1,250) + hb_eol() )

cInicio := substr( xContent,1,hb_at(hb_eol(),xContent)-2 ) //chr(13)+chr(10)

outstd("inicio do, " + cArq + ": " + hb_eol() + cInicio + hb_eol() )
cFim := cInicio + "--"
outstd("fim:" + hb_eol() + cFim + hb_eol() )

nInicio := hb_At("Content-Type:", xContent )
nInicio := hb_At(hb_eol(),xContent,nInicio) + 3
outstd("inicio:" + Str(nInicio) + hb_eol() )
nFim    := hb_At(cFim,xContent)-1

xFile   := substr(xContent,nInicio, (nFim - nInicio) )

hFileInput := hb_vfopen( cArq, FO_CREAT + FO_TRUNC + FO_WRITE)
hb_vfwrite(hFileInput,xFile)
hb_vfclose(hFileInput)

return OutStd("</pre></body></html>" )


Tem sua foto no zapzap, etc... pode enviar qualquer arquivo.
Se tem harbour tem CGI!

Saudações,
Itamar M. Lins Jr.
Avatar de usuário

Itamar M. Lins Jr.
Colaborador

Colaborador
 
Mensagens: 6927
Data de registro: 30 Mai 2007 11:31
Cidade/Estado: Ilheus Bahia
Curtiu: 309 vezes
Mens.Curtidas: 503 vezes



Retornar para Contribuições, Dicas e Tutoriais

Quem está online

Usuários vendo este fórum: Nenhum usuário registrado online e 22 visitantes


Ola Amigo, espero que meu site e forum tem lhe beneficiado, com exemplos e dicas de programacao.
Entao divulgue o link da Doacao abaixo para seus amigos e redes sociais ou faça uma doacao para o site forum...
MUITO OBRIGADO PELA SUA DOACAO!
Faça uma doação para o forum
cron
v
Olá visitante, seja bem-vindo ao Fórum Clipper On Line!
Efetue o seu login ou faça o seu Registro