After file transfer compressed and directly into the database read out and unzip the complete code

Source: Internet
Author: User
Tags rar
Transfer:
Set myfileobject=server.createobject ("Scripting.FileSystemObject")
Myfileobject.copyfile server. MapPath ("newsfile/" &sSaveFileName& "), server. MapPath ("&sTitle&"/"&sSaveFileName&") "is the first source path, and the second is the target path, which can be a virtual path and a physical path.
Create and write. htm files:
Set oFSO = CreateObject ("Scripting.FileSystemObject")
Set Otextstream = ofso.createtextfile (server. MapPath ("" &sTitle& ") &"/"&sTitle&". htm ", true"
Otextstream.write Scontenta
Otextstream.close
Compressed files:
Dim Cmddirr,rarnamedirr,rarsourcedirr
Cmddirr=server.mappath ("dos") & "/" cmd.exe and Rar.exe stored paths
Rarnamedirr=server.mappath ("Content") & "/" &sTitle& "" ' Compressed to RAR name and path
Rarsourcedirr=server.mappath ("" & Stitle & "") & "' The file path and name to compress
Dim Cmd,shell
cmd=cmddirr& "cmd.exe/c" &CmdDirr& "Rar.exe a-ep1-o+"-ep1-o+ are two switch commands specific reference to WinRAR help
cmd=cmd&rarnamedirr& "" &rarsourcedirr
On Error Resume Next
Set Shell = Server.CreateObject ("Wscript.Shell")
If Err or IsObject (Shell) =false Then
If ERR Then Err.Clear
Response.Write "Does not manipulate shell permissions ..."
Response.End
End If
On Error Resume Next
Shell.run Cmd,1,true
If ERR Then
Err.Clear
Response.Write "Error compressing file, may not have permission to manipulate"

Response.End
End If
To write a compressed package into a database:
Szfilepath = "" &server. MapPath ("Content") & "&sTitle&". rar "' compressed package address and name
Set fso=server.createobject ("Scripting.FileSystemObject")
If FSO. FileExists (Szfilepath) Then ' to determine if a compressed file exists
Set Ffile=fso. GetFile (Szfilepath)
If ffile.size > 0 Then ' compressed file is empty
Dim objstream
Set objstream = Server.CreateObject ("ADODB. Stream ")
With Objstream
. Type = 1
. Mode = 0
. Open
. LoadFromFile Szfilepath
ORS ("D_jdpath"). AppendChunk objstream.read ' write into database
. Close
End With


Set objstream=nothing

Else
Response.Write "<script language= ' JavaScript ' >alert (' file does not exist. ') </script> "
End If
Set ffile=nothing
End If
Read from the database:
Szfpath = Server. MapPath ("./") & "/" &title& ". rar" ' Compressed file location
Set fso=createobject ("Scripting.FileSystemObject")
IF FSO. FileExists (Szfpath) Then ' to determine if there is any conflict between compressed file addresses
Fso. DeleteFile (Szfpath)
End IF
Dim objstream
Set objstream = Server.CreateObject ("ADODB. Stream ")
With Objstream
. Type = 1
. Mode = 0
. Open
. Write (RS ("D_jdpath")) ' read directly from the database, here's the database field type in MySQL for IMG in Access for OLE
. SaveToFile (Szfpath)
. Close
End With
Set objstream = Nothing
Extract files:
Dim Ylj,ywj,mlpath,shell,rarcomm,retcode,cmd,comm,fso
Mlpath=server. MapPath ("dos") & "/" ' Store paths for RAR.EXE and CMD.EXE
Ylj=server.mappath ("Data") & "/" The path after extracting the file
Ywj=server.mappath ("Data") & "/mmgg.rar" ' rar file to extract
Set Shell = Server.CreateObject ("Wscript.Shell")

rarcomm=mlpath& "cmd.exe/c" &Mlpath& "Rar.exe x-t-o+-p-"

cmd=rarcomm&ywj& "" &ylj
RetCode = Shell.run (cmd,1, False)
This is my focus on the director of the, come back to society ...

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.