Ver Mensaje Individual
  #5 (permalink)  
Antiguo 06/11/2006, 22:35
rpcultural
 
Fecha de Ingreso: noviembre-2006
Mensajes: 1
Antigüedad: 18 años, 6 meses
Puntos: 0
De acuerdo Este código gestiona un archivo, pero es fácil modificarlo para varios.

<%@LANGUAGE="VBSCRIPT"%>
<%response.buffer=true
Func = Request("Func")
if isempty(Func) Then
Func = 1
End if
Select Case Func
Case 1
%>

<table width="420" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#0066CC">
<tr>
<td bgcolor="#FFFFFF" bordercolor="#FFFFFF">
<div id="sombra" style="position:relative;height:50;top:0;text-align:center;filter:shadow(color=gray)">
<font color="#0066CC" size="6">Subir archivos al servidor.</font></DIV>
</td>
</tr>
</table>
<FORM ENCTYPE="multipart/form-data" ACTION="saveany.asp?func=2" METHOD=POST id=form1 name=form1>
<TABLE align="center" width="425" border="1" bordercolor="#0066CC" cellspacing="5" cellpadding="5">
<TR>
<TD>
<p><b><font color="#FFFFFF">a</font>Instrucciones:</b></p>
<ol>
<li><font color="#330066" size="2">Pulsa en el botón examinar y elige
el archivo de tu ordenador.</font></li>
<li><font color="#330066" size="2">Luego pulsa el botón subir. </font></li>
<li><font color="#330066" size="2">Espere, recibirá la notificación
al terminar de subir el archivo.</font></li>
</ol>
</TD>
</TR>
<TR>
<TD bordercolor="#0066CC"><STRONG><font color="#330066" size="2"><b><font color="#FFFFFF">a</font></b>Nombre
del archivo a subir ...</font></STRONG> <font size="2"> <b><font color="#FFFFFF"><br>
aa
<br>
a</font></b><b><font color="#FFFFFF">a</font></b>
<INPUT NAME=File1 SIZE=30 TYPE=file>
<b><font color="#FFFFFF">a</font></b><b><font color="#FFFFFF">a</font></b><b><font color="#FFFFFF">a
</font></b> </font>
<INPUT type="submit" value="Subir">
</TD>
</TR>
</TABLE>
</FORM>
<%
Case 2
ForWriting = 2
adLongVarChar = 201
lngNumberUploaded = 0

'Get binary data from form
noBytes = Request.TotalBytes
binData = Request.BinaryRead (noBytes)
'convery the binary data to a string
Set RST = CreateObject("ADODB.Recordset")
LenBinary = LenB(binData)

if LenBinary > 0 Then
RST.Fields.Append "myBinary", adLongVarChar, LenBinary
RST.Open
RST.AddNew
RST("myBinary").AppendChunk BinData
RST.Update
strDataWhole = RST("myBinary")
End if
'Creates a raw data file for with all
' data sent. Uncomment for debuging.
'Set fso = CreateObject("Scripting.FileSystemObject")
'Set f = fso.OpenTextFile(server.mappath(".") & "\raw.txt", ForWriting, True)
'f.Write strDataWhole
'set f = nothing
'set fso = nothing
'get the boundry indicator
strBoundry = Request.ServerVariables ("HTTP_CONTENT_TYPE")
lngBoundryPos = instr(1,strBoundry,"boundary=") + 8
strBoundry = "--" & right(strBoundry,len(strBoundry)-lngBoundryPos)
'Get first file boundry positions.
lngCurrentBegin = instr(1,strDataWhole,strBoundry)
lngCurrentEnd = instr(lngCurrentBegin + 1,strDataWhole,strBoundry) - 1
Do While lngCurrentEnd > 0
'Get the data between current boundry an
' d remove it from the whole.
strData = mid(strDataWhole,lngCurrentBegin, lngCurrentEnd - lngCurrentBegin)
strDataWhole = replace(strDataWhole,strData,"")

'Get the full path of the current file.
lngBeginFileName = instr(1,strdata,"filename=") + 10
lngEndFileName = instr(lngBeginFileName,strData,chr(34))
'Make sure they selected at least one fi
' le.
if lngBeginFileName = lngEndFileName and lngNumberUploaded = 0 Then

Response.Write "<H2> Ha ocurrido el siguiente error.</H2>"
Response.Write "Debes elegir un archivo para subir"
Response.Write "<BR><BR>Pulsa el botón volver, realiza la corrección."
Response.Write "<BR><BR><INPUT type='button' onclick='history.go(-1)' value='<< Volver' id='button'1 name='button'1>"
Response.End
End if
'There could be one or more empty file b
' oxes.
if lngBeginFileName <> lngEndFileName Then
strFilename = mid(strData,lngBeginFileName,lngEndFileName - lngBeginFileName)
'Creates a raw data file with data betwe
' en current boundrys. Uncomment for debug
' ing.
'Set fso = CreateObject("Scripting.FileSystemObject")
'Set f = fso.OpenTextFile(server.mappath(".") & "\raw_" & lngNumberUploaded & ".txt", ForWriting, True)
'f.Write strData
'set f = nothing
'set fso = nothing

'Loose the path information and keep just the file name.
tmpLng = instr(1,strFilename,"\")
Do While tmpLng > 0
PrevPos = tmpLng
tmpLng = instr(PrevPos + 1,strFilename,"\")
Loop

FileName = right(strFilename,len(strFileName) - PrevPos)

'Get the begining position of the file data sent.
'if the file type is registered with the browser then there will be a Content-Type
lngCT = instr(1,strData,"Content-Type:")

if lngCT > 0 Then
lngBeginPos = instr(lngCT,strData,chr(13) & chr(10)) + 4
Else
lngBeginPos = lngEndFileName
End if
'Get the ending position of the file dat
' a sent.
lngEndPos = len(strData)

'Calculate the file size.
lngDataLenth = lngEndPos - lngBeginPos
'Get the file data
strFileData = mid(strData,lngBeginPos,lngDataLenth)
'Create the file.
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(server.mappath("imagenes") & "\" & FileName,ForWriting, True)
f.Write strFileData
Set f = nothing
Set fso = nothing

lngNumberUploaded = lngNumberUploaded + 1

End if

'Get then next boundry postitions if any
lngCurrentBegin = instr(1,strDataWhole,strBoundry)
lngCurrentEnd = instr(lngCurrentBegin + 1,strDataWhole,strBoundry) - 1
loop


Response.Write "Archivo subido <BR>"
Response.Write "El archivo ya está en el servidor.<BR>"
Response.Write "Por su seguridad será redireccionado al inicio.<BR>"
Response.Write "<BR><BR><INPUT type='button' onclick='document.location=" & chr(34) & "menumoder.asp" & chr(34) & "' value='<< Volver' id='button'1 name='button'1>"
End Select
%>
</BODY>
</HTML>