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

M

Michel

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.inc"-->
<%
dim fileId
dim fileName
dim path
dim sql
dim rs
dim objFSO
dim objFile
dim objStream

fileId = Request.QueryString("fileId")

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

set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(path & fileId) Then
Set objFile = objFSO.GetFile(path & fileId)
' write header
Response.Clear
Response.AddHeader "Content-Disposition", "attachment; filename=" &
Server.URLEncode(fileName)
Response.AddHeader "Content-Length", objFile.Size
Response.ContentType = "application/octet-stream"
' get the data
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = 1 'adTypeBinary
Response.CharSet = "UTF-8"
objStream.LoadFromFile(path & fileId)
Response.BinaryWrite(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
%>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top