Requirements:
1. Server supporting WScript.Shell - most hosts won't allow this.
2. Command line zip utility called PKZIP25 - can be downloaded from here:
http://www.amitbb.co.il/Downloads/temp/PKZIP25.zip
source code:
usage sample code
1. Server supporting WScript.Shell - most hosts won't allow this.
2. Command line zip utility called PKZIP25 - can be downloaded from here:
http://www.amitbb.co.il/Downloads/temp/PKZIP25.zip
source code:
--ZipFiles.asp
<%
'---------------------------------------------------------
'CreateZipFile: creating zip file in the given path.
'strZipPath - full path for the zip file, including the zip file name.
'arrFilesPath - array of the files to be zipped, e.g. Array("C:*.exe", "C:test*.*")
'NOTE: this code requires PKZIP25.EXE utility in the same location
' as this file.
'---------------------------------------------------------
Sub CreateZipFile(strZipPath, arrFilesPath)
Const PKZIP_FILE_NAME="pkzip25.exe"
Dim strCommand, objShell, objFSO
Dim x
'first verify pkzip exists:
Set objFSO=Server.CreateObject("Scripting.FileSystemObject")
If Not(objFSO.FileExists( Server.MapPath(PKZIP_FILE_NAME) )) Then
Set objFSO=Nothing
Err.Raise 20000, "Zip File Creator", "zip utility not found: "&Server.MapPath(PKZIP_FILE_NAME)
End If
'delete current file, if exists:
If objFSO.FileExists(strZipPath) Then
objFSO.DeleteFile(strZipPath)
End If
Set objFSO=Nothing
'build batch command:
strCommand=Server.MapPath(PKZIP_FILE_NAME)&" -add "&strZipPath&" "
For x=0 To UBound(arrFilesPath)
strCommand=strCommand&arrFilesPath(x)
If x Next
'execute:
Set objShell=Server.CreateObject("WScript.Shell")
objShell.Run strCommand, 0, True 'wait!
'done.
Set objShell=Nothing
End Sub
%>
<%
'---------------------------------------------------------
'CreateZipFile: creating zip file in the given path.
'strZipPath - full path for the zip file, including the zip file name.
'arrFilesPath - array of the files to be zipped, e.g. Array("C:*.exe", "C:test*.*")
'NOTE: this code requires PKZIP25.EXE utility in the same location
' as this file.
'---------------------------------------------------------
Sub CreateZipFile(strZipPath, arrFilesPath)
Const PKZIP_FILE_NAME="pkzip25.exe"
Dim strCommand, objShell, objFSO
Dim x
'first verify pkzip exists:
Set objFSO=Server.CreateObject("Scripting.FileSystemObject")
If Not(objFSO.FileExists( Server.MapPath(PKZIP_FILE_NAME) )) Then
Set objFSO=Nothing
Err.Raise 20000, "Zip File Creator", "zip utility not found: "&Server.MapPath(PKZIP_FILE_NAME)
End If
'delete current file, if exists:
If objFSO.FileExists(strZipPath) Then
objFSO.DeleteFile(strZipPath)
End If
Set objFSO=Nothing
'build batch command:
strCommand=Server.MapPath(PKZIP_FILE_NAME)&" -add "&strZipPath&" "
For x=0 To UBound(arrFilesPath)
strCommand=strCommand&arrFilesPath(x)
If x
'execute:
Set objShell=Server.CreateObject("WScript.Shell")
objShell.Run strCommand, 0, True 'wait!
'done.
Set objShell=Nothing
End Sub
%>
usage sample code
--ZipTest.asp
<% Option Explicit %>
<!-- #include file="ZipFiles.asp" -->
<%
Call TestZipFile()
Sub TestZipFile()
'create zip and give link:
Call CreateZipFile(Server.MapPath("myzip.zip"), Array(Server.MapPath("images")&"*.*"))
Response.Write("download zip")
End Sub
%>
<% Option Explicit %>
<!-- #include file="ZipFiles.asp" -->
<%
Call TestZipFile()
Sub TestZipFile()
'create zip and give link:
Call CreateZipFile(Server.MapPath("myzip.zip"), Array(Server.MapPath("images")&"*.*"))
Response.Write("download zip")
End Sub
%>
