harris9999
asked on
Download a file but hide path
I have a page with shows a list of files on the server.
The link for each of files on this page is just:
download.asp?docid=5
On the download.asp I have code to pull the filename of the document and the path of it etc to get the proper url of the file on the server.
How do I let users download that file without showing them the full path?
I have tried
response.Redirect(url)
but when this is opened in the browser it displays the fill path of the file.
The link for each of files on this page is just:
download.asp?docid=5
On the download.asp I have code to pull the filename of the document and the path of it etc to get the proper url of the file on the server.
How do I let users download that file without showing them the full path?
I have tried
response.Redirect(url)
but when this is opened in the browser it displays the fill path of the file.
ASKER
I have tried that but am getting an error:
Microsoft VBScript compilation error '800a0414'
Cannot use parentheses when calling a Sub
/downloads/index.asp, line 24
Response.AddHeader("Conten t-Disposit ion","atta chment; filename=" & filename)
-------------------------- ---------- ---------- ---------- ---------- ---------- ^
My code is below.
Will the ContentType have to be changed every time. There will be a selection of different documents to download.
Microsoft VBScript compilation error '800a0414'
Cannot use parentheses when calling a Sub
/downloads/index.asp, line 24
Response.AddHeader("Conten
--------------------------
My code is below.
Will the ContentType have to be changed every time. There will be a selection of different documents to download.
url=docrootpath & rsDoc("DocFileName")
filename=rsDoc("DocFileName")
Response.Clear()
Response.ContentType="text/plain"
Response.AddHeader("Content-Disposition","attachment; filename=" & filename)
Response.TransmitFile(url)
Response.End()
Do it this way
url=docrootpath & rsDoc("DocFileName")
filename=rsDoc("DocFileName")
Response.Clear()
Response.ContentType="text/plain"
Response.AddHeader "Content-Disposition","attachment; filename=" & filename
Response.TransmitFile(url)
Response.End()
I found this a long time ago and have used it with success in many project.
Give it a shot.
(Change all the .asp.txt file to .asp )
Read the [readme.txt] for information on how to use it.
Have a good one.
Carrzkiss
downloader.zip
Give it a shot.
(Change all the .asp.txt file to .asp )
Read the [readme.txt] for information on how to use it.
Have a good one.
Carrzkiss
downloader.zip
ASKER
sunithnair,
With that I'm not getting the error popping up from IE
Internet Explorer cannot download downloads/ from localhost.
Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found.
The asp page calling it is:
http://localhost/downloads/index.asp
With that I'm not getting the error popping up from IE
Internet Explorer cannot download downloads/ from localhost.
Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found.
The asp page calling it is:
http://localhost/downloads/index.asp
Your url should be something like c:\files\file.txt and not an http url
ASKER
Ok, I have changed it.
But I am still getting the same error.
Code below again.
But I am still getting the same error.
Code below again.
url=docpath & rsDoc("DocFileName")
response.Write(url)
filename=rsDoc("DocFileName")
Response.Clear()
Response.ContentType="application/msword"
Response.AddHeader "Content-Disposition","attachment; filename=" & filename
Response.TransmitFile(url)
Response.End()
What is the error message? Can you please post the exact error message?
ASKER
Error in attached image.
error.gif
error.gif
Could be because the file path is not valid. Check the path in the "url" variable and see if it actually exists
ASKER
Tried that. Did a response.write(url) and the correct path to the file is written out.
Is Response.Transmit file a valid ASP method?
Is Response.Transmit file a valid ASP method?
Yes it is you can also try Response.WriteFile
Or try this instead
url=docpath & rsDoc("DocFileName")
response.Write(url)
filename=rsDoc("DocFileName")
Response.Clear()
Response.ContentType="application/msword"
Response.AddHeader "Content-Disposition","attachment; filename=" & filename
Response.TransmitFile(url)
Response.Flush();
Response.End()
OR
url=docpath & rsDoc("DocFileName")
response.Write(url)
filename=rsDoc("DocFileName")
Response.Clear()
Response.ContentType="application/msword"
Response.AddHeader "Content-Disposition","attachment; filename=" & filename
Response.WriteFile(url)
Response.Flush();
Response.End()
ASKER
Same Error with Response.WriteFile.
Even if I write the direct path into it.
e.g.
Response.WriteFile("C:\Doc uments and Settings\user\My Documents\My Websites\Website\uploads\d ocs\WordDo c.doc")
Even if I write the direct path into it.
e.g.
Response.WriteFile("C:\Doc
Did you try my above code with Response.Flush() added? Also copy the file path and try navigating to the path and see of the file exists when you paste this file path in the explorer address bar
ASKER
Yep it went to the file when I pasted it to the address bar.
Getting the same error with the Response.flush.
Getting the same error with the Response.flush.
Can you post a screenshot of the error message after moving the error message on top a bit so that I would be able to see the window below it. I need to see the window that says "0% of from localhost"
ASKER
There it is
error.gif
error.gif
ASKER
I have created a new page with the following 6 lines of code below in the code box.
With the path and filename typed in directly.
When I browse to that page I get the error:
Microsoft VBScript runtime error '800a01b6'
Object doesn't support this property or method: 'Response.TransmitFile'
/test.asp, line 5
With the path and filename typed in directly.
When I browse to that page I get the error:
Microsoft VBScript runtime error '800a01b6'
Object doesn't support this property or method: 'Response.TransmitFile'
/test.asp, line 5
<%
Response.Clear()
Response.ContentType="application/msword"
Response.AddHeader "Content-Disposition","attachment; filename=WordDoc.doc"
Response.TransmitFile("C:\Documents and Settings\User\My Documents\My Websites\Web Folder\uploads\docs\WordDoc.doc")
Response.Flush()
Response.End()
%>
harris9999:
You are having a lot of problems with the code that you are using.
Have you tried what I have uploaded?
I got it to work with all the sites that I have used it with, without any problems what-so-ever.
Give it a shot, and I certain you will like it.
You are having a lot of problems with the code that you are using.
Have you tried what I have uploaded?
I got it to work with all the sites that I have used it with, without any problems what-so-ever.
Give it a shot, and I certain you will like it.
ASKER
carrzkiss,
That code just response.redirects to the file which will display its path on the server which I don't want if possible.
That code just response.redirects to the file which will display its path on the server which I don't want if possible.
ASKER
I have got it working with the code below:
Set objStream = Server.CreateObject("ADODB .Stream")
Which method is better. Does This one load the file in the server memory?
Set objStream = Server.CreateObject("ADODB
Which method is better. Does This one load the file in the server memory?
sPath = "C:\Documents and Settings\User\My Documents\My Websites\webFolder\uploads\docs\WordDoc.doc"
sName = "WordDoc.doc"
ContentType = "application/octet-stream"
Response.Buffer = True
Const adTypeBinary = 1
Response.Clear
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile sPath
ContentType = "application/octet-stream"
Response.AddHeader "Content-Disposition", "attachment; filename=""" & sName & """"
Response.Charset = "UTF-8"
Response.ContentType = ContentType
Response.BinaryWrite objStream.Read
Response.Flush
objStream.Close
Set objStream = Nothing
I just opened the file up, and you are right.
Wondering what happen to the other codes that I had.
If you all do not figure this one out before I get back, I will find it and upload it here.
Sorry for the wrong upload here.
Wondering what happen to the other codes that I had.
If you all do not figure this one out before I get back, I will find it and upload it here.
Sorry for the wrong upload here.
I am sorry I did a bit a of research and founf that the Response.WriteFile and Response.TransferFile is actually in ASP.NET and Set objStream = Server.CreateObject("ADODB .Stream") is the possible way to do this in ASP. Sorry for the confusion..
ASKER
sunithnair,
Thanks anyway it got me on the right track.
So does Set objStream = Server.CreateObject("ADODB .Stream") load the file into server memory? before it is downloaded?
Would it have problems if it was a large file being downloaded?
Thanks anyway it got me on the right track.
So does Set objStream = Server.CreateObject("ADODB
Would it have problems if it was a large file being downloaded?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Cheers,,
Lol, was actually just reading that thread at the minute.
Thanks!
Lol, was actually just reading that thread at the minute.
Thanks!
I cannot find what I use to use, but I did find this one, and it works like an absolute charm.
Add to a page: (Example)
download.asp?fname=myfile. ext
OK.
The script you can hide the file in any folder location that you want.
'-- my "secret" path
p = "g:\File-Storage"
You can store your files anywhere.
Right neat little code.
Found here:
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=7832&lngWId=4
Have a good one and hope this will help.
Carrzkiss
Add to a page: (Example)
download.asp?fname=myfile.
OK.
The script you can hide the file in any folder location that you want.
'-- my "secret" path
p = "g:\File-Storage"
You can store your files anywhere.
Right neat little code.
Found here:
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=7832&lngWId=4
Have a good one and hope this will help.
Carrzkiss
<%
'-- DOWNLOAD.ASP
'
'-- Simple Download Method With Streams
' Daniel Verzellesi
'
' As an example I'm getting the file I want To download
' from the Request (//.../dowload.asp?fname=myfile1.doc).
' You can change it To Get the file name from a DB or
' anything else...
'
Dim p, st, f
'-- my "secret" path
p = "g:\"
'p = "c:\files\"
'-- file name
f = Request.QueryString("fname")
'-- Get file into stream
Set st = CreateObject("ADODB.Stream")
st.Open
st.Type = 1 'binary
st.LoadFromFile p & f
'-- send stream To response
Response.ContentType = "application/my-download"
Response.AddHeader "Content-Disposition", "attachment; filename=""" & f & """"
Response.BinaryWrite st.Read(-1) 'read all
Response.End
'-- close the stream
Set st = nothing
%>
ASKER
carrzkiss,
Yep thats the same as what I have posted above with the Stream Object.
I have it passing the file id in rather than the filename.
Also used the link from sunithnair to hopefully get around the issue of large files.
Yep thats the same as what I have posted above with the Stream Object.
I have it passing the file id in rather than the filename.
Also used the link from sunithnair to hopefully get around the issue of large files.
I am also looking at this one right now as well.
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=7312&lngWId=4
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=7312&lngWId=4
Well, that one screamed my CPU up to 100% trying to download WinXP's SP3 from a drive on the same computer as I am testing on.
Not a good one for you unfortunantly.
Good Luck
Have a Good one.
Carrzkiss
Not a good one for you unfortunantly.
Good Luck
Have a Good one.
Carrzkiss
Open in new window