Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    code for downloading AVI file

    Hai i am new to server side scripting, i am creating a web page in that there is an link called download if the user clicks at it it has to download the avi file stored in the database.
    it has to ask the user the specific location for saving.

    whats the code for downloading the file and save in the directory the user specifies.

    if you know please guide me

  • #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    i assume that your talking about a way to force the file to download instead of opening?

    try:

    PHP Code:
    Function DownloadFile(file)

        
    Dim strAbsFile
        Dim strFileExtension
        Dim objFSO
        Dim objFile
        Dim objStream

        strAbsFile 
    Server.MapPath(file)
        
    Set objFSO Server.CreateObject("Scripting.FileSystemObject")
        If 
    objFSO.FileExists(strAbsFileThen

            Set objFile 
    objFSO.GetFile(strAbsFile)
            
    Response.Clear

            Response
    .AddHeader "Content-Disposition""attachment; filename=" objFile.Name
            Response
    .AddHeader "Content-Length"objFile.Size
            Response
    .ContentType "application/octet-stream"

            
    Set objStream Server.CreateObject("ADODB.Stream")
            
    objStream.Open
            
    '-- set as binary
            objStream.Type = 1
            Response.CharSet = "UTF-8"
            '
    -- load into the stream the file
            objStream
    .LoadFromFile(strAbsFile)
            
    '-- send the stream in the response
            Response.BinaryWrite(objStream.Read)
            objStream.Close
            Set objStream = Nothing
            Set objFile = Nothing

        Else '
    objFSO.FileExists(strAbsFile)
            
    Response.Clear
            Response
    .Write("There is no such file.")
        
    End If

        
    Set objFSO Nothing
    End 
    Function 

  • #3
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you for the code,it will be very useful to me.

  • #4
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •