Get ready for BLACK FRIDAY shopping starting in

Forums

ASP

This topic is locked

Download file link not open

Posted 19 May 2004 03:44:07
1
has voted
19 May 2004 03:44:07 Greg LeBreck posted:
I heave PDF files that have links to them on web page. When the user clicks on them I want them to have to download the file not have it open. Is there a way to do this?

I'd like to be able to do it asp and php?

Replies

Replied 19 May 2004 10:49:50
19 May 2004 10:49:50 Vince Baker replied:
place a file tag instead of a tag.

Regards
Vince

DMX Talkzone Manager

Visit my home: www.chez-vince.com

VBScript | ASP | HTML | SQL | Oracle | Hosting
Replied 19 May 2004 14:52:21
19 May 2004 14:52:21 Greg LeBreck replied:
I have never done that before, could you give me an example?
Replied 19 May 2004 15:08:27
19 May 2004 15:08:27 Vince Baker replied:
if you know the location of the file on the server (c:/inetpub/wwroot/yoursite/doc.pdf for example) then you can enter that in the link properties box. If you dont know the file name you could try the Force download extension, have never used it myself but it should work for you if you dont know the file location.

Here is a link, just click on Bud Force Download on the page displayed.

www.basic-ultradev.com/extensions/index.asp?searchOn=download

Regards
Vince

DMX Talkzone Manager

Visit my home: www.chez-vince.com

VBScript | ASP | HTML | SQL | Oracle | Hosting
Replied 20 May 2004 14:23:26
20 May 2004 14:23:26 Andrew Watson replied:
Try this script...


<pre id=code><font face=courier size=2 id=code>
On Error Resume Next
varPathToFileStore = "D:\databases\dart\documents\" ' YOUR PATH
strPath = CStr(##YOUR FILENAME##)
'-- do some basic error checking for the QueryString
If strPath = "" Then
Response.Clear
Response.Write(strPath & "&lt;br&gt;"
Response.Write("No file specified."
Response.End
ElseIf InStr(strPath, ".." &gt; 0 Then
Response.Clear
Response.Write("Illegal folder location."
Response.End
ElseIf Len(strPath) &gt; 1024 Then
Response.Clear
Response.Write("Folder path too long."
Response.End
Else
Call DownloadFile(strPath)
End If

Private Sub DownloadFile(file)
'--declare variables
Dim strAbsFile
Dim strFileExtension
Dim objFSO
Dim objFile
Dim objStream
'-- set absolute file location
strAbsFile = varPathToFileStore & (file)
'-- create FSO object to check if file exists and get properties
Set objFSO = Server.CreateObject("Scripting.FileSystemObject"
'-- check to see if the file exists
If objFSO.FileExists(strAbsFile) Then
Set objFile = objFSO.GetFile(strAbsFile)
'-- first clear the response, and then set the appropriate headers
Response.Clear
'-- the filename you give it will be the one that is shown
' to the users by default when they save
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("No such file exists."
End If
Set objFSO = Nothing
End Sub
</font id=code></pre id=code>

You could get the path many ways..form a database for example or simply hardcoded.

it works great

:: Son, im Thirty.... ::

Reply to this topic