Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Ola Pessoal!!!
E o seguinte... tenho um Upload sem componentes que esta funcionando tudo beleza... n ha de reclamar nada dele... mas ele faz upload de qualquer arquivo, eu kero limitar isso... eu so kero que os usuarios facam uploads somente de arquivos do formato: JPG, GIF e PING...
alguem poderia me ajudar????
ai vai o codigo abaixo!!!! http://forum.imasters.com.br/public/style_emoticons/default/thumbsup.gif
upload_form2
<!-- #include file = "upload_funcoes.asp" --><%' Chamando Funções, que fazem o Upload funcionarbyteCount = Request.TotalBytesRequestBin = Request.BinaryRead(byteCount)Set UploadRequest = CreateObject("Scripting.Dictionary")BuildUploadRequest RequestBin' Recuperando os Dados Digitados ----------------------Nome = UploadRequest.Item("Nome").Item("Value")'email = UploadRequest.Item("email").Item("Value")'Nome=Upload.form("Nome")' Tipo de arquivo que esta sendo enviadotipo_foto = UploadRequest.Item("foto").Item("ContentType")' Caminho completo dos arquivos enviadoscaminho_foto = UploadRequest.Item("foto").Item("FileName")' Nome dos arquivos enviadosnome_foto = Right(caminho_foto,Len(caminho_foto)-InstrRev(caminho_foto,"\"))' Conteudo binario dos arquivos enviadosfoto = UploadRequest.Item("foto").Item("Value")' pasta onde as imagens serao guardadaspasta = Server.MapPath("Img/")nome_foto = "/"&nome_foto'nome_foto = nome_foto' pasta + nome dos arquivoscfoto = "Img/lojas" + nome_foto' Fazendo o Upload do arquivo selecionadoif foto <> "" thenSet ScriptObject = Server.CreateObject("Scripting.FileSystemObject")Set MyFile = ScriptObject.CreateTextFile(pasta & nome_foto)For i = 1 to LenB(foto) MyFile.Write chr(AscB(MidB(foto,i,1)))NextMyFile.Closeend if----------------------------------------------------
upload.asp
<%@LANGUAGE="VBSCRIPT"%><%Sub BuildUploadRequest(RequestBin)'Get the boundaryPosBeg = 1PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)boundaryPos = InstrB(1,RequestBin,boundary)'Get all data inside the boundariesDo until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--"))) 'Members variable of objects are put in a dictionary object Dim UploadControl Set UploadControl = CreateObject("Scripting.Dictionary") 'Get an object name Pos = InstrB(BoundaryPos,RequestBin,getByteString("Content-Disposition")) Pos = InstrB(Pos,RequestBin,getByteString("name=")) PosBeg = Pos+6 PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34))) Name = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg)) PosFile = InstrB(BoundaryPos,RequestBin,getByteString("filename=")) PosBound = InstrB(PosEnd,RequestBin,boundary) 'Test if object is of file type If PosFile<>0 AND (PosFile<PosBound) Then 'Get Filename, content-type and content of file PosBeg = PosFile + 10 PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34))) FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg)) 'Add filename to dictionary object UploadControl.Add "FileName", FileName Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:")) PosBeg = Pos+14 PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13))) 'Add content-type to dictionary object ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg)) UploadControl.Add "ContentType",ContentType 'Get content of object PosBeg = PosEnd+4 PosEnd = InstrB(PosBeg,RequestBin,boundary)-2 Value = MidB(RequestBin,PosBeg,PosEnd-PosBeg) Else 'Get content of object Pos = InstrB(Pos,RequestBin,getByteString(chr(13))) PosBeg = Pos+4 PosEnd = InstrB(PosBeg,RequestBin,boundary)-2 Value = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg)) End If 'Add content to dictionary objectUploadControl.Add "Value" , Value 'Add dictionary object to main dictionaryUploadRequest.Add name, UploadControl 'Loop to next object BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)LoopEnd Sub'String to byte string conversionFunction getByteString(StringStr)For i = 1 to Len(StringStr) char = Mid(StringStr,i,1)getByteString = getByteString & chrB(AscB(char))NextEnd Function'Byte string to string conversionFunction getString(StringBin)getString =""For intCount = 1 to LenB(StringBin)getString = getString & chr(AscB(MidB(StringBin,intCount,1))) NextEnd Function%>----------------------------------------------------
Upload_funcoes.asp
<%Sub BuildUploadRequest(RequestBin)on error resume nextPosBeg = 1PosEnd = InStrB(PosBeg, RequestBin, getByteString(Chr(13)))boundary = MidB(RequestBin, PosBeg, PosEnd - PosBeg)BoundaryPos = InStrB(1, RequestBin, boundary)Do Until (BoundaryPos = InStrB(RequestBin, boundary & getByteString("--"))) Dim UploadControl Set UploadControl = CreateObject("Scripting.Dictionary") Pos = InStrB(BoundaryPos, RequestBin, getByteString("Content-Disposition")) Pos = InStrB(Pos, RequestBin, getByteString("name=")) PosBeg = Pos + 6 PosEnd = InStrB(PosBeg, RequestBin, getByteString(Chr(34))) Name = getString(MidB(RequestBin, PosBeg, PosEnd - PosBeg)) PosFile = InStrB(BoundaryPos, RequestBin, getByteString("filename=")) PosBound = InStrB(PosEnd, RequestBin, boundary) If PosFile <> 0 And (PosFile < PosBound) Then PosBeg = PosFile + 10 PosEnd = InStrB(PosBeg, RequestBin, getByteString(Chr(34))) FileName = getString(MidB(RequestBin, PosBeg, PosEnd - PosBeg)) UploadControl.Add "FileName", FileName Pos = InStrB(PosEnd, RequestBin, getByteString("Content-Type:")) PosBeg = Pos + 14 PosEnd = InStrB(PosBeg, RequestBin, getByteString(Chr(13))) ContentType = getString(MidB(RequestBin, PosBeg, PosEnd - PosBeg)) UploadControl.Add "ContentType", ContentType PosBeg = PosEnd + 4 PosEnd = InStrB(PosBeg, RequestBin, boundary) - 2 Value = MidB(RequestBin, PosBeg, PosEnd - PosBeg) Else Pos = InStrB(Pos, RequestBin, getByteString(Chr(13))) PosBeg = Pos + 4 PosEnd = InStrB(PosBeg, RequestBin, boundary) - 2 Value = getString(MidB(RequestBin, PosBeg, PosEnd - PosBeg)) End If UploadControl.Add "Value", Value UploadRequest.Add Name, UploadControl BoundaryPos = InStrB(BoundaryPos + LenB(boundary), RequestBin, boundary)LoopEnd SubFunction getByteString(StringStr)For i = 1 To Len(StringStr) Char = Mid(StringStr, i, 1) getByteString = getByteString & ChrB(AscB(Char))NextEnd FunctionFunction getString(StringBin)getString = ""For intCount = 1 To LenB(StringBin) getString = getString & Chr(AscB(MidB(StringBin, intCount, 1)))NextEnd Function%>
Carregando comentários...