Ian Turner 20/09/04
With many sites now offering pay for download material the issue of hotlinking and the publication of the link by customers is of significant financial interest to web sites.
This little script gives a small segment of ASP that prevents customers finding out the actual name of the file that they are downloading, thus preventing them from creating a link and hotlinking the file.
The code makes use of the ADODB Stream object to force a binary stream download, by using a different name in the ASP when writing the header information the original filename can be concealed from the customer so that the file can't be hotlinked.
"asp start marker"
Dim Strm
Dim Dfile
Dim FileName
Dim ViewFileName
FileName = "thedocument.pdf"
ViewFileName = "UserDocument1.pdf"
Response.ContentType = "application/octet-stream"
Response.AddHeader "content-disposition", "attachment; filename=" & ViewFileName
Set Strm = server.CreateObject("ADODB.Stream")
Strm.Open
Strm.LoadFromFile Server.MapPath(FileName)
Dfile = Strm.ReadText
Response.BinaryWrite Dfile
Strm.Close
Set Strm = Nothing
"asp end marker"
To implement this just put the code into an ASP file and ensure that the download link points to the ASP file the download will start automatically when the link is clicked.
Return to Programming News