Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Launch File in browser (if supported) and hide path to file

Status
Not open for further replies.

FateFirst

Programmer
Apr 15, 2002
212
GB
Hey community!

Just a quick question...

I have done a quick script for a client for downloading files without passing path information through to the user etc using ADODB.Stream. Thats working fine...

The client now also wants the user to be able to just open the file up in the browser (If supported. It doesnt matter if it isnt as it will force a download then anyways). So for files like PDFs, Excel etc they will open up in the browser.

Is there a way to do this without also giving away path information for the file?

I will probably not look to do anything like this but is there also a way check if the file can be opened in the users browser (do they support the filetype etc)?

Thanks.

- FateFirst
 
The files exist within a sub-directory of the website.

Root/download.asp
Root/files/file.doc

Its just a mini-document library. Users can log in and search various documents (searches information within a database that has been uploaded by the client).

Then if the user has the permission, he/she can click on a link to Download the file. Instead of telling the user to 'Right Click > Goto Save As' etc I put in a script to force the download dialog (ADODB.Stream) so the user just needs to click on the link. The client also wishes to have some sort of 'View' button too which basically just links straight to the file so he/she can open this file up in their browser if it supports it. Similar to excel, PDFs etc. If the browser doesnt support this then usually the file download dialog is initiated by default.

What I dont want to do is give the full path to the file which is why I was wondering if there was some way of doing something similar above.

Hope that makes more sense ;)

- FateFirst
 
OK, well here is the code I have written to enumerate existing files in a folder and create links for them.

You should be able to work with that.

I'd appreciate it if you shared your code that forces the download option. That might come in handy some time.

Code:
<%@ LANGUAGE="VBSCRIPT" %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="The Spider's Parlor">
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>Customer Support Download Page</TITLE>
</HEAD>
<BODY>
<!--
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' COPYRIGHT (c) 2004 All Rights Reserved
' DATE  : 3/16/2004
-->

<table height=100%>
<tr>
	<td bgcolor="84A5C6" width=17% height=100%></td>
	<td valign=top>
		
		<%

		
		set directory=server.createobject("scripting.filesystemobject")
		set allfiles=directory.getfolder(server.mappath("/download2/"))
		
		' Lists all the files found in the directory
		For each directoryfile in allFiles.files 
				
			%>
			<a href=/download2/<%
			' Write out the name of the document
			response.write server.urlencode(directoryfile.name) %>><% response.write directoryfile.name %></a><br>
		<% 
				
		' End for next loop to list documents
		next 
				
		%> 
		
		
	</td>
	<td bgcolor="84A5C6" width=17% height=100%></td>
</tr>
</table>


</BODY>
</HTML>

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top