download file with [1] at the end of the file name

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michel

    download file with [1] at the end of the file name

    Hi,
    I've the code bellow who give me a file to download.
    The files are sored in a folder. The filename is the id of the data stored
    in a table.
    The name of the file at the download time will be the one stored in the
    table.
    The problem is that if the file name in the table is toto.doc the browser
    propose me to save it at toto.doc[1]
    How can I get rid of the [1]
    The file can be of any tipe.

    <!--#include file="header.in c"-->
    <%
    dim fileId
    dim fileName
    dim path
    dim sql
    dim rs
    dim objFSO
    dim objFile
    dim objStream

    fileId = Request.QuerySt ring("fileId")

    sql = "select * from file where id_file = " & fileId
    set rs = Server.CreateOb ject("ADODB.Rec ordset")
    Call rs.Open(sql, conn, adOpenStatic, adLockReadOnly)
    fileName = rs("fileName")
    path = Server.MapPath( "file") & "\"

    set objFSO = Server.CreateOb ject("Scripting .FileSystemObje ct")
    If objFSO.FileExis ts(path & fileId) Then
    Set objFile = objFSO.GetFile( path & fileId)
    ' write header
    Response.Clear
    Response.AddHea der "Content-Disposition", "attachment ; filename=" &
    Server.URLEncod e(fileName)
    Response.AddHea der "Content-Length", objFile.Size
    Response.Conten tType = "applicatio n/octet-stream"
    ' get the data
    Set objStream = Server.CreateOb ject("ADODB.Str eam")
    objStream.Open
    objStream.Type = 1 'adTypeBinary
    Response.CharSe t = "UTF-8"
    objStream.LoadF romFile(path & fileId)
    Response.Binary Write(objStream .Read)
    objStream.Close
    Set objStream = Nothing
    Set objFile = Nothing
    else
    %>
    <html>
    <body>
    <h1>File not found</h1>
    </body>
    </html>
    <%
    end if
    set objFSO = Nothing
    %>




Working...