Implement online compression and decompression with ASP

xiaoxiao2021-03-30  195

First, the question is proposed

With the development of the interconnect, the number of websites increases in an amazing number. In addition to providing information services to the majority of netizens, they should also become a place to upload and download files. In the process of uploading and downloading, the transfer time is the key, which requires a faster transfer speed. In the case where the transmission speed is fixed or the upper and lower changes, the volume of the transfer file is minimized, it is a feasible approach: When the file is uploaded, the file to be uploaded will be compressed with WinRAR. After the upload is successful, after the upload is successful, in the website Replenishment by the program; when downloading the file, the file to be downloaded will be compressed by the program in the website and then download. This article discusses the solution to this problem. Second, the method and instructions First, to upload a WinRAR decompression program, WinRAR's own decompression program, only the core program rar.exe can be found, can be found in the WinRAR installation directory. Then you have to upload a program cmd.exe that performs RAR.exe is the program in the Windows operating system, which can be found in the system disk WinNT / System32 folder. After the two files are uploaded, you need to write some program code to implement compression and decompression. The file that implements the compression function is named Zip.asp, and the file that unzipped function is named unzip.asp. The program code contains the command line syntax of the WinRAR application. Let's take a brief introduction: WinRAR - - <@ list file ... > Command To WinRAR Run Character Combination Representative. Switch switching operation Specifies the definition of type, compressive strength, compressed file type, and so on. Compressed file names to be processed by compressed files. File names to be processed. The list file list file is a plain text that contains the name of the file name. The file name should be started in the first volume. An comment can be added after using // characters in the list file. For example, you can include two column strings create backup.lst: C: / Work / Doc / *. TXT // Backup text document C: / Work / Image / *. BMP // Backup Image C: / Work / Misc Then run: WinRAR A Backup @ backup.lst You can specify a normal file name and list file name in the command line. The decompression path is only used with commands E and X, with it. Indicates the location of the decompressed file. If the folder does not exist, it will be created automatically. Alphabel command list:

a Add files to compressed files

c Add compressed file annotation

d Delete files from the compressed file

e decompress compression from the compressed file, ignore the path

f refreshes the file in the compressed file

i Look for strings in a compressed file

K lock compressed files

m Move files and folders to compressed files

r Refract damaged compressed files

RC reconstruction of lost volumes

RN rename compressed file

RR [N] Add Data Recovery Record

RV [N] Create a recovery volume

S [Name] conversion compressed file becomes self-extracting file type

S-Delete Self-extracting module

t test compressed file

u Update the file from the compressed file

X Decompression compression from the compressed file with the full path name

The key to the program code is to use server.createObject ("wscript.shell") to perform cmd.exe, cmd.exe running Rar.exe to perform unzip files and compressed files through WinRAR commands. Third, the program list zip.asp program list:

<% 'main folder contains cmd.exe rar.exe, for example, to compress file (* .mdb)' 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 - - <@ list file ...> 'command: a - Add to the compressed file = 0 theRESPONSE.WRITE = 0 ThenResponse.write "command successfully ! "Elseresponse.write" command failed! Permissions are not enough or the program cannot run "end ifif err.Number <> 0 ThenResponse.write"

error Number: "& Err.NumberResponse.write"

Reason: " & Err.DescriptionResponse.write "

Error Source:" & Err.SourceResponse.write End IF%> Unzip.asp Program List:

<% 'main folder contains cmd.exe rar.exe to decompress file (* .rar)' Decompressed storage 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 - - <列 list file ...> 'command: x - full path unzip file' switch in compressed file: -r - Containers Clip 'switch: -O - Override existing file' switch: -O- - Do not override the existing file if Issuccess = 0 TheRESPONSE.WRITE "command successfully executed!" Elseresponse.write "command failed! Permissions are not enough or The program cannot run "end ifif err.number <> 0 TenResponse.write"

error number: "& err.NumberResponse.write"

reason: "& Err.DescriptionResponse.write"

Error Source: " & Err.SourceResponse.write End IF%> Four, conclusions This article uses RAR.exe and cmd.exe two files to implement online compression and unzipped websites in the ASP program. The implementation method is simple, the program code is small, and it can be used for practical programming. Especially in the case of your own server, it is extremely practical and convenient. The above programs are passed in Windows 200Sever and IIS5.0.

TRACKBACK: http://tb.blog.9cbs.net/trackback.aspx?postid=797249

转载请注明原文地址:https://www.9cbs.com/read-130715.html

New Post(0)