如何同时发送HTML和“另存为”文件? [英] How do I send HTML and a file for 'Save-As' at the same time?

查看:94
本文介绍了如何同时发送HTML和“另存为”文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


如果您将浏览器指向此页面,

http://prdownloads.sourceforge.net/v...use_mirror=umn


服务器向您发送HTML页面,之后很快就会提示您为要下载的文件执行另存为。 br />

如果没有经典的Headers already sent,他们怎么做呢?错误?


在我的申请中,我需要做一些非常相似的事情。


提前感谢您的帮助!


Eric

解决方案

如果你看一下你正在谈论的页面的html代码,你会注意到以下内容:


< META HTTP-EQUIV =" refresh" content =" 5;

URL = http://umn.dl.sourceforge.net/sourceforge/vnc-tight/tightvnc-1.2.9_x86_viewer.zip">


此行使文件在页面加载后5秒下载。

这通常用于重定向,但因为在这种情况下刷新(或

重定向)到一个zip文件,然后这不会替换页面,但提示

保存文件。


Dae

< ed ****** @ virtualcad.com>在消息中写道

news:11 ********************** @ o13g2000cwo.googlegr oups.com ...

您好,

如果您将浏览器指向此页面,

http://prdownloads.sourceforge.net/v...use_mirror=umn

他们是如何做的没有经典的Headers already sent错误?

在我的申请中,我需要做一些非常相似的事情。

提前感谢您的帮助!

Eric



你好,


好​​吧..这很有意义。我没有意识到它只是等待5秒

来为我提供一个已经存在的文件。我以为它正在处理一个

文件,并在它准备好后立即提供给我,这就是我需要的



我要为用户提供的文件可能需要3到30秒才能动态创建。如果我使用的值太低,页面将刷新到''找不到对象''。如果该值太高,则用户等待的时间超过了他们应该的时间。


这是我希望我的应用程序执行的操作:


1.用户点击链接。

2.服务器发送HTML页面解释可能需要30秒。

3服务器一旦准备好就立即发送提示另存为的文件。


如果除了步骤之外没有用户交互,我希望它更好

1.


这可能吗?


Eric

而不是刷新到静态文件,刷新到将要发送回文件的php文件。


让我们说当用户点击它带给他some_page.php的链接。在这个页面的

中你可以输入以下代码:


< META HTTP-EQUIV =" refresh" content =" 1;

URL = http://yoursite.com/some/folder/file_gen.php">


file_gen.php应该现在生成文件并将其发送回去下载。

如果没有关于这个生成文件的更多细节,我不能告诉你如何将它发送回来。

。但是这里有一个简单的例子,它会返回一个

动态创建的javasctipt来下载:


//生成文件并且其处理程序包含在

Hello,

If you point your browser to this page,

http://prdownloads.sourceforge.net/v...use_mirror=umn

the server sends you the HTML page, and very soon afterwards, you are
prompted to do a ''Save-As'' for a file to download.

How do they do that without the classic "Headers already sent" error?

In my application, I need to do something very similar.

Thanks in advance for any help!

Eric

解决方案

If you look at the html code of the page you''re talking about, you''ll notice
the following:

<META HTTP-EQUIV="refresh" content="5;
URL=http://umn.dl.sourceforge.net/sourceforge/vnc-tight/tightvnc-1.2.9_x86_viewer.zip">

This line makes the file to download 5 seconds after the page is loaded.
This is often used for redirection, but since in this case it refresh (or
redirect) to a zip file, then this doesn''t replace the page but prompt to
save the file instead.

Dae
<ed******@virtualcad.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...

Hello,

If you point your browser to this page,

http://prdownloads.sourceforge.net/v...use_mirror=umn

the server sends you the HTML page, and very soon afterwards, you are
prompted to do a ''Save-As'' for a file to download.

How do they do that without the classic "Headers already sent" error?

In my application, I need to do something very similar.

Thanks in advance for any help!

Eric



Hello,

OK .. that makes sense. I didn''t realize it was just waiting 5 seconds
to serve me a file that already exists. I thought it was processing a
file and serving it to me as soon as it was ready, which is what I need
to do.

The file I am going to serve the User can take anywhere from 3 to 30
seconds to create dynamically. If I use a value too low, the page will
refresh to ''Object not found''. If the value is too high, the User is
waiting longer than they should have to.

Here is what I want my application to do:

1. User clicks on a link.
2. Server sends HTML page explaining it may take up to 30 seconds.
3. Server sends file prompting a ''Save-As'' as soon as it is ready.

I would like it better if there was no User interaction other than step
1.

Is this possible?

Eric


Instead of refreshing to a static files, refresh to a php file that will
send back the file.

Lets say when the user click the link it brings him to some_page.php. In
this page you would put this code:

<META HTTP-EQUIV="refresh" content="1;
URL=http://yoursite.com/some/folder/file_gen.php">

file_gen.php should now generate the file and sent it back to be downloaded.
Without more detail about this generated file I can''t tell you how exactly
to send it back. But here is a simple exemple that would return a
dynamically created javasctipt to be downloaded:

// The file is generated and its handler is contained by


这篇关于如何同时发送HTML和“另存为”文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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