Descarga de archivos


<% 'Exige la declaración explícita de todas las variables en un archivo. 'option explicit %> <%Server.ScriptTimeout = 600%> <% 'Sirve para poder usar Response.End en cualquier momento Response.Buffer = True 'Si igualamos la propiedad a 0, la página caduca instantáneamente, con lo que se evita la caché Response.Expires = 0 %> <% Dim root_folder 'configuracion root 'root_folder = "c:\servidorweb" root_folder = Server.MapPath("\2016\descargas\") Dim colortitulo, colordirectorio, colorarchivos colortitulo = "#C7CCE0" colordirectorio = "#6581C0" colorarchivos = "#C7CCE0" Dim textotitulo, textodirectorio, textodirectorioenlace, textoarchivo, textoarchivoenlace textotitulo = "noticiatexto" textodirectorio = "noticiatexto" textodirectorioenlace = "noticiapaginacion" textoarchivo = "noticiatexto" textoarchivoenlace = "noticiapaginacion" %> <% ' SFManager v.1.3 ' Author: Khristoforov Yuri ' http://www.activex.net.ru Dim fs Set fs = Server.CreateObject("Scripting.FileSystemObject") Dim curr_dir,curr_dir2, temp_arr curr_dir2 = Request.QueryString("dir") if InStr(1, curr_dir2, "..") <> 0 then Response.Write "donde vas!" Response.End end if ' Llama todo el cotorro Call Main() Set fs = Nothing Sub Main() %> <% curr_dir = root_folder & curr_dir2 temp_arr = ShowDirList(curr_dir) temp_arr = SortStr(temp_arr) %>
<% Call Main_Print(temp_arr,1) temp_arr = ShowFilesList(curr_dir) temp_arr = SortStr(temp_arr) Call Main_Print(temp_arr,0) %>
 Carpeta actual: DESCARGAS <%=Replace(curr_dir2, "\", "\ ")%> Carpeta Principal
<% Erase temp_arr End Sub '''''''Ver Archivos'''''''' Function ShowFilesList(folder) Dim f, f1, fc, i ReDim farr(0) Set f = fs.GetFolder(folder) Set fc = f.Files i=0 For Each f1 In fc farr(i) = CStr(f1.Name) i = i + 1 ReDim Preserve farr(i) Next ShowFilesList = farr End Function '''''''Ver Directorios'''''''' Function ShowDirList(folder) Dim f, f1, fc, i ReDim dirarr(0) Set f = fs.GetFolder(folder) Set fc = f.SubFolders i=0 For Each f1 In fc dirarr(i) = CStr(f1.Name) i = i + 1 ReDim Preserve dirarr(i) Next ShowDirList = dirarr End Function ''''''Ordena??''''''' Function SortStr(arr) Dim t,i,j For j = 0 To UBound(arr)-1 For i = j + 1 To UBound(arr)-1 If StrComp(CStr(arr(i)), CStr(arr(j)), vbTextCompare) < 0 Then t = arr(j) arr(j) = arr(i) arr(i) = t End If Next Next SortStr = arr End Function Sub Main_Print(arr,flag) ' flag=1 - êàòàëîãè ' flag=0 - ôàéëû Dim i,k,tmp, edit_file i = 0 Select Case flag Case 1 If curr_dir2 <> "" Then 'Los dos .. para volver para atras k = InStrRev(curr_dir2,"\") If k <> 0 Then tmp = Mid(curr_dir2,1,k-1) Response.Write "" Response.Write "" & " " & "" Response.Write "" & " .. " & "    " End If End If For i = 0 To UBound(arr)-1 Response.Write "" Response.Write "" & "" & _ "" Response.Write "" & arr(i) & _ " " & GetFolderLastModified(root_folder & curr_dir2 & "\" & arr(i)) & "  " & FormatSize(GetFolderSize(root_folder & curr_dir2 & "\" & arr(i))) & " " Next Case 0 For i = 0 To UBound(arr)-1 Response.Write "" Response.Write "Descargar Archivo" Response.Write "" & arr(i) & " " & GetFileLastModified(root_folder & curr_dir2 & "\" & arr(i)) & "  " & FormatSize(GetFileSize(root_folder & curr_dir2 & "\" & arr(i))) & " " Next End Select End Sub Function FormatSize(Size) If NOT IsNumeric(Size) OR Size="" Then FormatSize="" ElseIf Size=0 Then FormatSize="0B" ElseIf Size>1024*1024*1024 Then FormatSize=Round(Size/1024/1024/1024,1) & "GB" ElseIf Size>10*1024*1024 Then FormatSize=Round(Size/1024/1024) & "MB" ElseIf Size>1024*1024 Then FormatSize=Round(Size/1024/1024,1) & "MB" ElseIf Size<100 Then FormatSize=Size & "B" ElseIf Size<1024 Then FormatSize="1kB" ElseIf Size>100*1024 AND Size<=1024*1024 Then FormatSize=Round(Size/1024/1024,1) & "MB" Else FormatSize=Round(Size/1024) & "kB" End If End Function Function GetFileSize(fl_path) Dim f Set f = fs.GetFile(fl_path) GetFileSize = f.Size End Function Function GetFileLastModified(fl_path) Dim f, d, fday, fmonth, fyear Set f = fs.GetFile(fl_path) d = f.DateLastModified fday = CStr(Day(d)) fmonth = CStr(Month(d)) fyear = CStr(Year(d)) If (Len(fmonth) = 1) Then fmonth = "0" & fmonth End If If (Len(fday) = 1) Then fday = "0" & fday End If GetFileLastModified = fday & "." & fmonth & "." & fyear End Function Function GetFolderLastModified(fo_path) Dim f, d, fday, fmonth, fyear Set f = fs.GetFolder(fo_path) d = f.DateLastModified fday = CStr(Day(d)) fmonth = CStr(Month(d)) fyear = CStr(Year(d)) If (Len(fmonth) = 1) Then fmonth = "0" & fmonth End If If (Len(fday) = 1) Then fday = "0" & fday End If GetFolderLastModified = fday & "." & fmonth & "." & fyear End Function Function GetFolderSize(fo_path) Dim f Set f = fs.GetFolder(fo_path) GetFolderSize = f.Size End Function Function GetExtImg(strIn) Dim ext, res ext = fs.GetExtensionName(strIn) res = "" ' Esta es la formula que enseña el icono correspondiente if fs.FileExists(Server.MapPath("./iconos/" & ext & ".gif")) then res = "iconos/" & ext & ".gif" else res = "iconos/file.gif" end if GetExtImg = res End Function Function GetExt(strIn) Dim ext ext = LCase(fs.GetExtensionName(strIn)) GetExt = ext End Function %>