By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,687 Members | 1,509 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,687 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
%>


Jul 19 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.