Click to See Complete Forum and Search --> : Server redirect??


konithomimo
03-04-2005, 07:00 PM
I'm not quite sure where to put this thread, but this seems like the best place. I was wondering if there is a way to have my server redirect to a file when a link is followed. For example:

How would I go about making it so that when people click on a link on my site they are sent to my server for the file and then redirected to the actual file that they want which is in another folder, or on one of my other servers? I do not want to link directly to the file.

phpnovice
03-04-2005, 07:30 PM
I don't think there is an automated way of doing this. You can, however, have an ASP page that can serve up selected files, based on the request received -- so that there is no direct link to those files via the browser.

konithomimo
03-05-2005, 08:54 AM
And what would be the basic script for a page like that? I was fairly sure that an asp page would be the best way to do it, but I am new to asp so I still dont get how to do it.

russell
03-05-2005, 10:37 AM
what type of file? asp? txt?

lets say it's an ASP file, but you don't want them to see the url, so they can't link directly to it (for whatever reason, tho i cant think of one). We'll call it FileHideMe.asp.

in a different file (the one the link points to)

<%
Server.Execute("FileHideMe.asp")
%>

phpnovice
03-05-2005, 01:55 PM
Originally posted by konithomimo
And what would be the basic script for a page like that?
OK, firstly, I presume that you're talking about serving up a file for download but you don't want to use a link to the file. Let's say you want them to have to pay for the download first. OK? At any rate...

Your ASP page would use code similar to this to serve up such a file for download:

Set adoStream = Server.CreateObject("ADODB.Stream")
adoStream.Open()
If fileType = "binary" Then
adoStream.Type = adTypeBinary
Else
adoStream.Type = adTypeText
End If
adoStream.LoadFromFile Server.MapPath(filePath & fileName)
If adoStream.Type = adTypeBinary Then
stream = adoStream.Read()
Else
stream = adoStream.ReadText()
End If
adoStream.Close()
Set adoStream = Nothing
'
Response.Buffer = True
Response.AddHeader "content-disposition", "attachment; filename=" & fileName
Response.AddHeader "content-length", Len(stream)
Response.ContentType = mimeType
Response.BinaryWrite stream
Response.Flush