Implementation of online compression and decompression using ASP

Source: Internet
Author: User
Tags command line contains rar zip backup

First, the question of the proposed

With the development of the Internet, the number of Web sites increased by an astonishing number. The role of the site in addition to the vast numbers of users to provide information services, but also should become netizens to upload and download the file site. In the process of uploading and downloading files, transmission time is the key, which requires a faster transmission speed. In the transmission speed fixed or up or down changes in the case, as far as possible to reduce the volume of transmission files, is a feasible way: Upload files, the first file to be uploaded with WinRAR compression, upload success in the site through the program to achieve the decompression; when downloading files, The file will be downloaded in the Web site through the program to achieve compression and then download. This paper discusses the solution to the problem.


Ii. Method and Description

First of all to upload a winrar decompression program, is winrar own decompression program, only need its core program RAR.EXE this file can be, in the WinRAR installation directory can be found. Then you want to upload a program that executes RAR.EXE CMD. EXE This is the Windows operating system program, in the system disk Winnt/system32 folder can be found. After uploading the two files, you need to write some program code to achieve compression and decompression.

may wish to realize the compression function file name is zip.asp, realizes the decompression function the file name is unzip.asp.

The program code contains the command line syntax for the WinRAR application, which is briefly described below:

WinRAR < command >-< switch 1>-< switch n> < compressed file > < file ...> <@ list file ...> < decompression path \>

command to WinRAR the character combination that is running to represent the feature.

Switch switching operations specify type, compression strength, compressed file type, and so on.

Compressed file name to be processed by the cabinet.

File name to be processed by the file.

A list file list file is a plain text that contains the name of the file you want to work with. The filename should be started in the first volume. You can add a comment after the//character is used in the list file. For example, you can include two column strings to create a backup.lst:c:\work\doc\*.txt//Backup Text document C:\WORK\IMAGE\*.BMP//Backup picture C:\work\misc and then run: WinRAR a backup @ Backup.lst You can specify both the normal file name and the list file name on the command line.

The decompression path is used in combination with the command e and X. Indicates the location where the extracted file was added. If the folder does not exist, it is created automatically.


Alphabetical command list:

A add file to compressed file C add compressed file comment
D remove file from compressed file E Extract compression from compressed file, ignore path
F Refresh files in compressed file I find a string in a compressed file
K Lock compressed file m move files and folders to compressed files
R repair damaged compressed files RC Rebuild lost volumes
RN Rename compressed file Rr[n] Add data recovery record
Rv[n] Create a recovery volume S[name] Convert a compressed file into a self-extracting file type
S-delete self-extracting module T test compressed file
U update file x from compressed file to extract compression from compressed file with full path name

In fact, the key to the program code is to use Server.CreateObject ("Wscript.Shell") to perform Cmd.exe,cmd.exe run RAR.EXE through the WinRAR command to perform uncompressed files and compressed files.


Iii. List of procedures

Zip. ASP Program list:


<%
' main folder contains Cmd.exe Rar.exe For example: Files to compress (*.mdb)
' compressed storage directory is Main\data.rar
On Error Resume Next
Unzip_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> < compressed file > < file ...> <@ list file ...>
< decompression path \>
Command: A-added to a compressed file
If issuccess = 0 Then
Response.Write Command successfully executed! The
Else
Response.Write command failed to execute! Insufficient permissions or the program cannot run "
End If
if Err.Number <> 0 then
Response.Write" <p> Error Number: "& Err.Number
Response.Write "<p> Reason:" & Err.Description
Response.Write "<p> Error Source:" & Err.Source
Response.Write
End If
%>


UNZIP. ASP Program list:
<%
' Main folder contains Cmd.exe Rar.exe files to extract (*.rar)
' Unpacked storage directory as main
On Error Resume Next
Unzip_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> < compressed file > < file ...> <@ list file ...>
< decompression path \>
' Command: X-Extract files from full path in compressed file
' Switch:-R-Together with subfolders
' Switch:-o+-overwrite files already in existence
' Switch:-o--do not overwrite files that already exist
If issuccess = 0 Then
Response.Write "Command executed successfully! "
Else
Response.Write Command Execution failed! Insufficient permissions or the program cannot run
End If
If Err.Number <> 0 Then
Response.Write "<p> Error Number:" & Err.Number
Response.Write "<p> Reason:" & Err.Description
Response.Write "<p> Source of Error:" & Err.Source
Response.Write
End If
%>


Iv. Conclusion

This article is done by using RAR.EXE and CMD. EXE of these two files, in the ASP programming in the online compression and decompression of the Web site file function. The implementation method is simple, the program code is few, can use for reference in the practical programming. Especially in the case of owning your own server is extremely practical and convenient. The above program runs through Windows2000sever and IIS5.0.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.