Ir para conteúdo
Fórum Script Brasil
  • 0

Upload


AlexCT

Pergunta

5 respostass a esta questão

Posts Recomendados

  • 0

********************* UpLoad.aspx ********************************

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head>

<title>UpLoad</title>

<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">

<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">

<meta name="vs_defaultClientScript" content="JavaScript">

<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">

</head>

<body MS_POSITIONING="GridLayout">

<form enctype="multipart/form-data" runat="server" id="Form1">

Selecione o arquivo a ser transferido: <input id="uploadedFile" type="file" runat="server" name="uploadedFile">

<p><input type="button" id="upload" value="Enviar" onserverclick="Upload_Click" runat="server" name="upload">

<p>

<asp:Label id="message" runat="server" />

</p>

</form>

</body>

</html>

********************* UpLoad.aspx ********************************

*****************************************************************

*****************************************************************

********************* UpLoad.aspx.vb ******************************

Dim savePath As String = "c:\"

Sub Upload_Click(ByVal source As Object, ByVal e As EventArgs)

If Not (uploadedFile Is Nothing) Then

Try

Dim postedFile = uploadedFile.PostedFile

Dim filename As String = System.IO.Path.GetFileName(postedFile.FileName)

Dim contentType As String = postedFile.ContentType

Dim contentLength As Integer = postedFile.ContentLength

postedFile.SaveAs(savePath & filename)

message.Text = postedFile.Filename & " uploaded " & _

"<br>Formato: " & contentType & _

"<br>Tamanho: " & contentLength.ToString()

Catch exc As Exception

message.Text = "Erro na Transferência"

End Try

End If

End Sub

********************* UpLoad.aspx.vb ******************************

Link para o comentário
Compartilhar em outros sites

  • 0

O ANTERIOR é ASP.NET

Se acessar o site http://aspalliance.aspin.com/home/componen...cob=aspalliance verá vários em ASP3

Exemplo.asp

<!-- #include file="clsComLessUpload.asp" -->

<html>

<head>

<title>Untitled Document</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<body>

<%

Server.ScriptTimeout = 2000000000

If Request.ServerVariables("CONTENT_LENGTH") <> 0 Then

Set upload = New CUpload

'upload.Save Server.MapPath("\"),"arquivo1",true

'upload.Save "f:\","arquivo2",true

'upload.SaveAs "myfile",Server.Mappath("/"),"arquivo",true %>

Nome: <%= upload.form("nome")%><br>

<% set upload = nothing

else %>

<form action="exemplo.asp" method="post" enctype="multipart/form-data">

  <table width="300" border="0" align="center" cellpadding="3" cellspacing="0">

    <tr>

      <td>Nome:</td>

      <td><input name="nome" type="text" value="" size="100"></td>

    </tr>

    <tr>

      <td>E-mail:</td>

      <td><input name="email" type="text"></td>

    </tr>

    <tr>

      <td>Arquivo 1:</td>

      <td><input name="arquivo1" type="file"></td>

    </tr>

    <tr>

      <td>Arquivo 2:</td>

      <td><input name="arquivo2" type="file"></td>

    </tr>

    <tr>

      <td>&nbsp;</td>

      <td><input name="acao" type="submit" id="acao" value="Upload"></td>

    </tr>

  </table>

</form>

<% End If %>

</body>

</html>

**************************************************************

**************************************************************

**************************************************************

clsComLessUpload.asp

<%

Class CUpload

Private aAllData

Private aHdr

Private isPosted

Private q

'---------------------------------------------------------------------------

' Constructor

'---------------------------------------------------------------------------

Private Sub Class_Initialize()

  If Request.TotalBytes > 0 Then

  Dim AllDataB, x

 

  ' Set flag for posted data

  isPosted = True

 

  ' Retrieve post data

  q = Chr(34)

  aAllDataB = Request.BinaryRead(Request.TotalBytes)

 

  ' Convert to Ascii from Unicode

  For x = 1 To LenB(aAllDataB)

  aAllData = aAllData & Chr(AscB(MidB(aAllDataB, x, 1)))

  Next

 

  ' Retrieve header

  aHdr = Left(aAllData, InStr(aAllData, vbCrLf) + 1)

  Else

  isPosted = False

  End If

End Sub

   

'---------------------------------------------------------------------------

' Destructor

'---------------------------------------------------------------------------

Private Sub Class_Terminate()

  '

End Sub

 

'---------------------------------------------------------------------------

' Save with original filename

'---------------------------------------------------------------------------

Public Function Save(directory, field, overwrite) 'As Boolean6

  If isPosted Then

  Dim filename

 

  filename = directory & GetFileName(field)

  SaveFile field,filename,overwrite

  End If

End Function

'---------------------------------------------------------------------------

' Save with different filename

'---------------------------------------------------------------------------

Public Function SaveAs(filename, directory, field, overwrite) 'As Boolean

  If isPosted Then

  Dim filenameAll

 

  filenameAll = directory & filename

  SaveFile field,filenameAll,overwrite

  End If

End Function

'---------------------------------------------------------------------------

' Look for the specified form field in the data, retrieve its filename

'---------------------------------------------------------------------------

Public Function GetFileName(field)

  If isPosted Then

  Dim x2, i

  x = InStr(aAllData, aHdr & "Content-Disposition: form-data; name=" & q & field & q)

  If x >0 Then

    x = InStr(x, aAllData, "filename=" & q)

    x2 = InStr(x, aAllData, vbCrLf)

   

    For i = x2 To x Step -1

    If Mid(aAllData, i, 1) = "\" Then

      x = i - 9

      Exit For

    End If

    Next

   

    GetFileName = Mid(aAllData, x + 10, x2 - (x + 11))

  End If

 

  End If

End Function

   

'---------------------------------------------------------------------------

' Get file data from upload, for a specified field

'---------------------------------------------------------------------------

Private Function GetFileData(field)

  Dim x2

  x = InStr(aAllData, aHdr & "Content-Disposition: form-data; name=" & q & field & q)

  If x > 0 Then

  x = InStr(x, aAllData, vbCrLf)

  x = InStr(x + 1, aAllData, vbCrLf)

  x = InStr(x + 1, aAllData, vbCrLf) + 2

  x2 = InStr(x, aAllData, Left(aHdr, Len(aHdr) - 2))

 

  GetFileData = Mid(aAllData, x + 2, x2 - x - 4)

  End If

End Function

   

'---------------------------------------------------------------------------

' Create an FSO object, save the data to disk

'---------------------------------------------------------------------------

Private Sub SaveFile(aField, aFilename, overwrite) 'As Boolean

  Dim FSO, TS

 

  Set FSO = CreateObject("Scripting.FileSystemObject")

  Set TS = FSO.CreateTextFile(aFilename, overwrite, False) ' final param is unicode

 

  TS.Write GetFileData(aField)

  TS.Close

 

  Set TS = Nothing

  Set FSO = Nothing

End Sub

   

'---------------------------------------------------------------------------

' Pega o campo texto do formulário

'---------------------------------------------------------------------------

Public Function Form(field)

  Dim x2

  x = InStr(aAllData, aHdr & "Content-Disposition: form-data; name=" & q & field & q)

  If x > 0 Then

  x = InStr(x, aAllData, vbCrLf)

  x = InStr(x + 1, aAllData, vbCrLf)

  x = InStr(x + 1, aAllData, vbCrLf) + 2

  x2 = InStr(x, aAllData, Left(aHdr, Len(aHdr) - 2))

 

  Form = Mid(aAllData, x, x2 - x - 2)

  End If

End Function

End Class

%>

T +

MACUL

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,3k
    • Posts
      652,3k
×
×
  • Criar Novo...