自动从 HTML 传输文件
我正在构建一个 Web 应用程序,指导用户完成应用程序的配置和安装。 它动态构建一组配置文件,然后将它们与应用程序的安装程序一起以存档(.ZIP 文件)的形式发送。 该网页是从 Linux shell 脚本生成的(抱歉),出于安全原因,我希望直接从脚本发送文件,而不是作为链接发送,因此用户无法直接访问它。
过程如下:用户输入一些信息并且生成文件后,我想显示一个包含说明的页面,然后自动开始下载,而不要求用户单击“下载此文件”链接:
#!/bin/bash
echo_header_and_instructions # Standard HTML
<Magic HTML tag to start transfer> # ??? What goes here???
command_to_stream_the_files # Probably 'cat'
echo_end_tags # End the page.
谢谢你的帮助!
I'm building a web application that guides my users through the configuration and installation of an application. It builds a set of configuration files dynamically, then sends them in an archive (.ZIP file) along with an installer for the application. The web page is generated from a linux shell script (sorry), and for security reasons, I'd prefer the file be sent directly from the script, rather than as a link, so the user can't access it directly.
Here's the process: Once the user has entered some information, and the files have been generated, I want to display a page with instructions, then start the download automatically, without asking the user to click a "download this file" link:
#!/bin/bash
echo_header_and_instructions # Standard HTML
<Magic HTML tag to start transfer> # ??? What goes here???
command_to_stream_the_files # Probably 'cat'
echo_end_tags # End the page.
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为你真的不能这么做。
您可以通过以下标头强制下载文件,但据我所知,您不能混合 HTML 和文件下载。
标题:
内容长度不是强制性的,但使用它可以确保下载对话框可以显示还有多少文件需要下载。
您可以做的一件事是使用 javascript 重新加载页面。 因为该页面是文件下载,所以原始 HTML 页面将保留在原处:
You Can't really do that I think.
You can force the file download through the following headers but as far is I know you can't mix HTML and file download.
Headers:
The content length is not mandatory but using it will make sure that the download dialog box can show how much more file there is to download.
A thing you could do is reload the page using javascript. Because the page is a file download the original HTML page will stay in place:
我认为您可以使用 元标记 让浏览器提示用户下载文件进行刷新,但正如 Pim Jager 所说,我认为您无法通过一次传输来完成此操作。 你也许可以尝试做类似的事情:
I think you can make the browser prompt the user to download a file by using the meta tag to do a refresh, but as Pim Jager said I don't think you can do it with one transfer. You could maybe try doing something like:
一位朋友提供了魔法:使用
标签创建一个仅包含要下载的文件的“不可见”框架:
A friend supplied the magic: use an
<iframe>
tag to create an "invisible" frame that contains only the file to download: