在我的网页上提示文件下载

时间:2022-10-12 21:11:36

I wanted to serve a download of my program on special download page. Something like: http://site.com/download, where there will be a standard HTML page and also a file download prompt. I was wondering how I'd go about implementing this.

我想在特殊下载页面上下载我的程序。类似于:http://site.com/download,其中将有一个标准的HTML页面和一个文件下载提示。我想知道我将如何实现这一点。

The only way I can think of is having a hidden iframe in the page pointing to the file the user wants to download. I also know of the PHP function readfile() but I don't see how I can implement that on the page aswell as have a HTML output shown to the user.

我能想到的唯一方法是在页面中有一个隐藏的iframe,指向用户想要下载的文件。我也知道PHP函数readfile()但我没有看到如何在页面上实现它以及向用户显示HTML输出。

Any help is appreciated, thanks.

任何帮助表示赞赏,谢谢。

2 个解决方案

#1


3  

You can use a META redirect, which since it points to a download will not leave the page you're on.

您可以使用META重定向,因为它指向下载不会离开您所在的页面。

On your HTML page, try including something like this:

在您的HTML页面上,尝试包含以下内容:

<META HTTP-EQUIV="REFRESH" CONTENT="1;URL=/download/sitefile.zip">

This will browse to the file after 1 second, which should prompt the visitor to download it without leaving the page.

这将在1秒后浏览到该文件,这将提示访问者在不离开页面的情况下下载它。

#2


0  

You can have the site http://example.com/download this can be normal html site. With redirection after few seconds (can be done in js or meta).

您可以访问http://example.com/download这个网站,这可能是普通的html网站。几秒后重定向(可以在js或meta中完成)。

It should redirect to PHP site with fpassthru() function in it. That way you can easily implement additional security in the PHP.

它应该重定向到PHP站点,其中包含fpassthru()函数。这样,您就可以轻松地在PHP中实现额外的安全性。

HINT: make sure to set proper HEADERS in the PHP file so browsers will start download the file instead of showing the content in browser screen.

提示:确保在PHP文件中设置正确的HEADERS,以便浏览器开始下载文件而不是在浏览器屏幕中显示内容。

#1


3  

You can use a META redirect, which since it points to a download will not leave the page you're on.

您可以使用META重定向,因为它指向下载不会离开您所在的页面。

On your HTML page, try including something like this:

在您的HTML页面上,尝试包含以下内容:

<META HTTP-EQUIV="REFRESH" CONTENT="1;URL=/download/sitefile.zip">

This will browse to the file after 1 second, which should prompt the visitor to download it without leaving the page.

这将在1秒后浏览到该文件,这将提示访问者在不离开页面的情况下下载它。

#2


0  

You can have the site http://example.com/download this can be normal html site. With redirection after few seconds (can be done in js or meta).

您可以访问http://example.com/download这个网站,这可能是普通的html网站。几秒后重定向(可以在js或meta中完成)。

It should redirect to PHP site with fpassthru() function in it. That way you can easily implement additional security in the PHP.

它应该重定向到PHP站点,其中包含fpassthru()函数。这样,您就可以轻松地在PHP中实现额外的安全性。

HINT: make sure to set proper HEADERS in the PHP file so browsers will start download the file instead of showing the content in browser screen.

提示:确保在PHP文件中设置正确的HEADERS,以便浏览器开始下载文件而不是在浏览器屏幕中显示内容。

相关文章