First, add a complete code
<!--Name - ASP online decompression, compression tool copyright -VeVb Wulin.com (www.vevb.com)--><%@LANGUAGE=VBSCRIPT CODEPAGE=936%><title>Welcome to use ASP online decompression, compression tool< /title><body><TABLE border=0 width=80% align=center cellpacing=1 cellpadding=3 style=FONT-FAMILY: Verdana;font-size:14px;BORDER: #000000 1px solid;background-color:# f7f7f7><tr><th width=100% height=24 bgcolor=#33CCFF> </th></tr><tr><td bgcolor=#33CCFF><%Server.ScriptTimeout=99999Dim winrar,cmddirWinrar=C:/Program Files/WinRAR/Winrar.exe 'Compression The address of the file (Winrar) cmddir=%windir%/system32/cmd.exe 'cmd.exe' address of the address of the command prompt user=csissp 'The user name of this program pwd=csissp 'Login, compression, and decompression of this program Password, please be sure to modify (at least 8 digits combined passwords are safe!) if request.Form(user)=user and request.Form(pwd)=pwd thenresponse.write The path of this folder: &Server.Mappath(.)&<br>from=request.Form(from)where=request.Form(where)if from<> and where<> then Dim a,b,Shell,Runing,Runcode,Cmd if instr(where,:)=0 then a=Server.mappath(&where&) else a=where if instr(from,:)=0 then b=Server.mappath (&from&) else b=from 'response.Write b if right(b,1)<>/ and left(right(b,4),1)<>. then b=b&.rar On Error Resume Next Set Shell = Server.CreateObject(WScript.Shell) if request.QueryString(action)=1 then 'Decompress if not ReportFileStatus(b)then Response.Write(Not found&b& may not exist! ):Response.End() Runing= cmddir& /c &winrar& x -ibck -t -y -o+ -p&pwd& 'Set the command to run the decompression. Cmd=Runing&b& &a&/ elseif request.QueryString(action)=0 then 'Compress file if (not ReportFileStatus(a)) and (not ReportFolderStatus(a)) then Response.Write(Not Found &a& may not exist!):Response. End() Cmd= cmddir& /c del /f /q &b Runcode = Shell.Run(Cmd,1,True) Runing= cmddir& /c &winrar& a -ibck -y -ep -o+ -p&pwd& 'Compression. Cmd=Runing&b& &a else 'Delete the file Cmd= cmddir& /c del /f /q &b end if Runcode = Shell.Run(Cmd,1,True) Runing = Shell.Run(cmddir& /c taskkill /im winrar.exe,1 ,false) Runing = Shell.Run(cmddir& /c exit,1,false) Set Shell=nothing ErrInfo%> <%else%><form name=frm method=post action=?action=1 style=BORDER: #d9d9d9 1px solid;background-color:#f7f7f7>------------------------------------------<strong> Unzip the file</strong>---------------------------------------------------<br>< br>Please enter the rar compressed file address: <input name=from value=1.rar size=50><br>Decompress to: <input name=where value=. size=50>Folder please use absolute path and at the end Add / <br><br><input name=submit type=submit value= Unzip><input type=hidden name=user value=<%=request.Form(user)%>><input type=hidden name=pwd value=<%=request.Form(pwd)%>></FORM><form name=frm method=post action=?action=0 style=BORDER: #d9d9d9 1px solid;background-color :#f7f7f7>----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- >-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- The address of the file you want to compress: <input name=where value=./data/dvbbs7#.mdb size=50>You can also enter the folder<br><br>Storage path and new file name: <input name=from value=../data/1.rar size=50>Originally overwrite the file with the same name<br>< br><input name=submit type=submit value= Compression><input type=hidden name=user value=<%=request.Form(user)%>><input type=hidden name=pwd value=<%=request .Form(pwd)%>></FORM><%ErrInfoend ifelselogin()end ifSub ErrInfo if not isempty(Runcode) and Runcode=0 Then Response.Write(The operation is executed successfully, the operation you submitted is as follows:<br>& Cmd) elseif not isempty(Runcode) then Response.Write(The operation is executed failed! Maybe your permissions are insufficient or the program cannot run in DOS (command prompt). The operation you submitted is as follows: <br> & Cmd) else end if If Err Then Response.Write <br>&err.descriptionerr.Clear End If %><form name=frm method=post action=?action=2 style=BORDER: #d9d9d9 1px solid;background-color:#f7f7f7>--------------------- ------------------<strong>Delete Files</strong>-------------------------- ------------------<br><br>Please enter the address to delete the file: <input name=from size=50 value=<%=from%>>Folder Please use the absolute path and add / at the end / <br><input type=hidden name=where value=<%if where<> then response.Write where else response. Write .%>><br><input name=submit type=submit value= Delete><input type=hidden name=user value=<%=request.Form(user)%>><input type=hidden name=pwd value=<%=request.Form(pwd)%>></FORM><br><%End SubFunction ReportFileStatus(filespec) Dim fso Set fso = CreateObject(Scripting.FileSystemObject) ReportFileStatus=false If (fso.FileExists(filespec)) Then ReportFileStatus = true Set fso = nothingEnd FunctionFunction ReportFolderStatus(fldr) Dim fso Set fso = CreateObject(Scripting.FileSystemObject ) ReportFolderStatus=false If (fso.FolderExists(fldr)) Then ReportFolderStatus = true Set fso =nothingEnd FunctionSub login()%><form name=frm method=post action=?action=2 style=BORDER: #d9d9d9 1px solid;background-color:#f7f7f7> <p>--- --------------------------<strong>Login System</strong>----- -------------------------------<br> <br>User name: <input name=user value=csissp> </p>Password: <input name=pwd type=password id=pwd> <br> <br> <input name=submit type=submit value= Login></FORM><%End sub%></td></tr><tr> <td height=22 align=center bgcolor=#FFFFFF>Copyright ©2008 <a href =//www.vevb.com>VeVb Wulin.com</a></td></tr></table></body>
How to use:
1. Upload directly to any directory on the server (virtual host) (preferably the root directory)
2. Use a browser to access the Winrar.asp file address
3. Enter the account number and password (default account number: csisp Default password: csisp)
4. Enter the address of the Winrar file (*.RAR) and confirm it and decompress it.
5. Enter the address of the file you want to compress, and after confirmation, you can compress it!
Special reminder: The file address is the relative address of this Winrar system!
The server using this program must be installed with WinRar (usual servers are installed)
The default program address of this program is suitable for more than 99% of servers (virtual hosts)
If the address is incorrect, you can modify it yourself. The address is the address where you installed WINRAR (virtual host users, please contact your virtual host customer service)
The following details and supplements
1. Problem raising
As the Internet develops, the number of websites has increased with amazing numbers. In addition to providing information services to netizens, the website should also become a place for netizens to upload and download files. During the process of uploading and downloading files, transmission time is the key, which requires a faster transmission speed. When the transmission speed is fixed or the up and down changes little, it is a feasible way to minimize the volume of the transferred file: when uploading the file, first compress the file to be uploaded with WINRAR, and after the upload is successful, it will be in the website. Decompression is achieved through the program; when downloading a file, first compress the file to be downloaded through the program within the website and then download it. This article discusses the solution to this problem.
2. Methods and instructions
First, you need to upload a WINRAR decompression program, which is WINRAR's own decompression program. You only need its core program RAR.EXE file, which can be found in the WINRAR installation directory. Then you want to upload a program that executes RAR.EXE. CMD.EXE. This is a program in the WINDOWS operating system. You can find it in the WINNT/SYSTEM32 folder of the system disk. After uploading these two files, you need to write some program code to implement compression and decompression.
You might as well name the file that implements the compression function ZIP.ASP, and the file that implements the decompression function UNZIP.ASP.
The program code contains the command line syntax of the application WINRAR, and the following is a brief introduction:
WinRAR <Command> -<Switch 1> -<Switch N> <Compressed File> <File...> <@List File...> <Decompressed Path/>
The character combination that the command to run by WinRAR represents the function.
Switch switch operation defines the type, compression strength, compression file type, etc.
The compressed file name to process.
The file name to be processed.
List Files List Files are plain text containing the name of the file to be processed. The file name should be started on volume 1. You can add comments after using // characters in the list file. For example, you can create backup.lst:c:/work/doc/*.txt //Back up text document c:/work/image/*.bmp //Back up image c:/work/misc and Next run: winrar a backup @backup.lst You can specify both normal filename and list filename in the command line.
The decompression path is only used with commands e and x. Indicates where the decompressed file was added. If the folder does not exist, it will be created automatically.
List of letter commands:
| a Add file to compressed file | c Add compressed file comments |
| d Delete file from compressed file | e Decompress from compressed file, ignore path |
| f Refresh the file in the compressed file | i Find strings in compressed files |
| k Locking compressed files | m Move files and folders to compressed files |
| r Repair damaged compressed files | rc rebuild missing volume |
| rn rename the compressed file | rr[N] Add data recovery record |
| rv[N] Create a recovery volume | s[name] converts compressed files into self-extracted file type |
| s- Delete the self-extracting module | t Test compressed files |
| u Update files from compressed files | x Decompress from compressed file with full path name |
In fact, the key point in the program code is to use Server.CreateObject(Wscript.Shell) to execute CMD.EXE. CMD.EXE runs RAR.EXE to execute decompressed files and compressed files through WINRAR commands.
3. Procedure list
ZIP.ASP program list:
<%'main folder contains cmd.exe rar.exe For example: the file to be compressed (*.mdb)' The compressed storage directory is main/data.raron error resume nextunzip_path=Server.mappath(main)&/Set WshShell = server.CreateObject(Wscript.Shell)IsSuccess = WshShell.Run (winrar a &unzip_path&data &unzip_path&*.mdb,1, False)'WinRAR <Command> -<Switch 1> -<Switch N> <Compress File> <File. ..> <@list file...> <Decompress path/>' command: A - Add to compressed file if IsSuccess = 0 The thenResponse.write command was executed successfully! The elseResponse.write command failed to execute! The permissions are insufficient or the program cannot run end ifif err.number <> 0 thenResponse.Write <p>Error number: & Err.numberResponse.Write <p>Reason: & Err.descriptionResponse.Write <p>Error source: & Err. SourceResponse.Write end if%>
UNZIP.ASP program list:
<%'main folder contains cmd.exe rar.exe file to be decompressed (*.rar) 'The decompressed directory is mainon error resume nextunzip_path=Server.mappath(main)&/Set WshShell = server. CreateObject(Wscript.Shell)IsSuccess = WshShell.Run (winrar x -r -o+ &unzip_path&*.rar &unzip_path&,1, False)'WinRAR <Command> -<Switch 1> -<Switch N> <Compress File> <File. ..> <@list file...> <Decompress path/> 'Command: X - Decompress file full path from compressed file' switch: -R - with subfolder' switch: -O+ - Overwrite the existing file' switch: -O- - Not overwrite the existing file if IsSuccess = 0 ThenResponse.write command executes successfully! The elseResponse.write command failed to execute! The permissions are insufficient or the program cannot run end ifif err.number <> 0 thenResponse.Write <p>Error number: & Err.numberResponse.Write <p>Reason: & Err.descriptionResponse.Write <p>Error source: & Err. SourceResponse.Write end if%>
4. Conclusion
This article uses RAR.EXE and CMD.EXE to realize the function of online compression and decompressing files in websites in ASP programming. The implementation method is simple and there is little program code, which can be used for reference and use during practical programming. Especially when you have your own server, it is extremely useful and convenient. The above program is run under Windows 2000Sever and IIS 5.0.