ASP页面打开/下载文件 [英] ASP page to open/download a file

查看:72
本文介绍了ASP页面打开/下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个ASP页面来打开/下载文件


在fileview.jsp中,我有文件浏览,当用户点击提交按钮时,

fileview2.asp应该打开文件。


fileview.asp

============

< FORM ACTION =" fileview2.asp" method =" POST">

< P>< input type =" FILE" name =" filename">

< P>< input type =" submit">


fileview2.asp

============

<%

String filename = Request.Form(" filename")

Response.Redirect = filename

%>


但是,这不起作用。有任何想法吗?请告知我缺少的东西。

谢谢!!

I want to write a ASP page to open/download a file

In fileview.jsp, I have the file browse, and when user click submit button,
fileview2.asp should open the file.

fileview.asp
============
<FORM ACTION="fileview2.asp" method="POST">
<P><input type="FILE" name="filename">
<P><input type="submit">

fileview2.asp
============
<%
String filename = Request.Form("filename")
Response.Redirect = filename
%>

However, this is not working. any ideas? please advise what I am missing.
thanks!!

推荐答案

用你似乎在描述的内容,你想要发生

是:


1.带表格的用户加载页面。

2.用户浏览并选择一个文件。

3.用户提交表格。

4.文件上传到服务器。

5.服务器SAVES文件到文件系统。

6.浏览器被重定向到这个保存的文件。


首先,String filename = Request.Form(" filename")"不是有效的代码。

" filename = Request.Form(" filename")"没关系,但那只是返回

< input type = file>中的文件路径。框。


要将实际文件上传并保存到服务器,您需要使用

上传组件.1你想要使用该组件将文件保存到

文件系统,然后将用户重定向到该文件系统。


< sidenote>为什么要这样做,无论如何?这有点奇怪。如果我想打开一个存在于我的文件系统上的文件,那么我的自然反应就不会是将文件上传到网站以便它可以转向并且给它

回到我身边。但是,他自己的每一个。< / sidenote>


处理文件上传,请看这里:
http://www.aspfaq.com/show.asp?id=2189

之前任何服务器端都适合你,记下表单标签的ENCTYPE

值。


---------- ----------------------


现在我开始尝试重定向了用户在他的机器上的

文件。这是真的?如果是这样的话,我也觉得这很奇怪,但是那个'b $ b罚款。 :]如果是这种情况,你可以这样做:


<%

if request.form(" filename") <> ""然后response.redirect

request.form(" filename")

%>


< form method =" ;交" action =" default.asp">

< input type =" file"名称= QUOT;文件名" />

< input type =" submit" />

< / form>

雷在家


1您可以在没有组件的情况下处理文件上传使用纯粹的

VB / Jscripting,但建议不要这样做。

" Matt" <毫安******* @ hotmail.com>在留言中写道

news:u0 ************* @ TK2MSFTNGP12.phx.gbl ...
With what you seem to be decribing, the action that you want to take place
are:

1. User load page with form.
2. User browses for and selects a file.
3. User submits form.
4. File is uploaded to server.
5. Server SAVES file to file system.
6. Browser is redirected to this saved file.

First of all, "String filename = Request.Form("filename")" isn''t valid code.
"filename = Request.Form("filename")" would be okay, but that''d just return
the file path that was in the <input type=file> box.

To get the actual file uploaded and saved to the server, you need to use an
upload component.1 You''d want to use that component to save the file to the
file system and then redirect the user to it.

<sidenote>Why do you want to do this, anyway? It''s kinda odd. If I want to
open a file that exists on my file system, my natural reaction would not be
to upload the file to a web site so that it can then turn around and give it
right back to me. But, to each his own.</sidenote>

For handling file uploads, see here:
http://www.aspfaq.com/show.asp?id=2189
Before anything server-side will work for you, make note of the ENCTYPE
value of the form tag.

--------------------------------

Now I''m beginning to thing that you''re trying to redirect the user to the
file on his machine. Is this true? If so, I also find this odd, but that''s
fine. :] If that''s the case, you can do something like this:

<%
if request.form("filename") <> "" Then response.redirect
request.form("filename")
%>

<form method="post" action="default.asp">
<input type="file" name="filename" />
<input type="submit" />
</form>
Ray at home

1 You can process file uploads without a component and just use pure
VB/Jscripting, but advise against this.
"Matt" <ma*******@hotmail.com> wrote in message
news:u0*************@TK2MSFTNGP12.phx.gbl...
我想写一个ASP页面打开/下载文件

在fileview.jsp中,我有文件浏览,当用户点击提交
按钮时,fileview2.asp应该打开文件。

fileview.asp
============
< FORM ACTION =" fileview2.asp" method =" POST">
< P>< input type =" FILE" name =" filename">
< P>< input type =" submit">

fileview2.asp
======== ====
<%
String filename = Request.Form(" filename")
Response.Redirect = filename
%>
但是,这不起作用。有任何想法吗?请告知我缺少的内容。
谢谢!!
I want to write a ASP page to open/download a file

In fileview.jsp, I have the file browse, and when user click submit button, fileview2.asp should open the file.

fileview.asp
============
<FORM ACTION="fileview2.asp" method="POST">
<P><input type="FILE" name="filename">
<P><input type="submit">

fileview2.asp
============
<%
String filename = Request.Form("filename")
Response.Redirect = filename
%>

However, this is not working. any ideas? please advise what I am missing.
thanks!!



您要访问的文件在哪里?


如果它在您的服务器上.....检查以确保路径正确

重定向


如果它在客户端计算机上,你没有希望使用重定向,因为它需要首先将
上传到你的服务器。


-


问候


Steven Burn

Ur IT Mate Group
www.it-mate.co.uk


保持免费!

" Matt" <毫安******* @ hotmail.com>在留言中写道

news:u0 ************* @ TK2MSFTNGP12.phx.gbl ...
Where is the file you are trying to access?

If it''s on your server..... check to make sure the path is correct before
re-directing

If it''s on the client machine, you''ve no hope of using redirecting as it
needs to be uploaded to your server first.

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
"Matt" <ma*******@hotmail.com> wrote in message
news:u0*************@TK2MSFTNGP12.phx.gbl...
我想写一个ASP页面打开/下载文件

在fileview.jsp中,我有文件浏览,当用户点击提交
按钮时,fileview2.asp应该打开文件。

fileview.asp
============
< FORM ACTION =" fileview2.asp" method =" POST">
< P>< input type =" FILE" name =" filename">
< P>< input type =" submit">

fileview2.asp
======== ====
<%
String filename = Request.Form(" filename")
Response.Redirect = filename
%>
但是,这不起作用。有任何想法吗?请告知我缺少的内容。
谢谢!!
I want to write a ASP page to open/download a file

In fileview.jsp, I have the file browse, and when user click submit button, fileview2.asp should open the file.

fileview.asp
============
<FORM ACTION="fileview2.asp" method="POST">
<P><input type="FILE" name="filename">
<P><input type="submit">

fileview2.asp
============
<%
String filename = Request.Form("filename")
Response.Redirect = filename
%>

However, this is not working. any ideas? please advise what I am missing.
thanks!!



..重定向实际上向标题中的浏览器发送指令

响应,所以你可以告诉浏览器重定向到本机的本地文件。 :]


Ray在家里


Steven Burn < pv*@noyb.com>在消息中写道

新闻:%2 **************** @ tk2msftngp13.phx.gbl ...
..Redirect actually sends an instruction to the browser in the header of the
response, so you can tell a browser to redirect to a file that is local to
the machine. :]

Ray at home

"Steven Burn" <pv*@noyb.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
其中是您要访问的文件是什么?

如果它在您的服务器上.....请在重定向之前检查路径是否正确
<如果它在客户端计算机上,你就没有希望使用重定向,因为它需要首先上传到你的服务器。

-



Steven Bu
Where is the file you are trying to access?

If it''s on your server..... check to make sure the path is correct before
re-directing

If it''s on the client machine, you''ve no hope of using redirecting as it
needs to be uploaded to your server first.

--

Regards

Steven Bu



这篇关于ASP页面打开/下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆