我想通过Php在服务器中编写一个文本文件,让客户端下载该文件.
我该怎么做?
本质上,客户端应该能够从服务器下载文件.
我使用的是ASP.NET2.0.我创建了一个包含一些输入字段和下载按钮的下载表单.单击下载按钮时,我想将用户重定向到"感谢您下载..."页面并立即向他/她提供要保存的文件.
我有以下代码来显示savefile对话框:
public partial class ThankYouPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
Response.AddHeader("Content-Disposition",
"attachment; filename=\"downloadedFile.zip\"");
Response.ContentType = "application/x-zip-compressed";
Response.BinaryWrite(this.downloadedFileByteArray);
Response.Flush();
Response.End();
}
}
Run Code Online (Sandbox Code Playgroud)
显然,此代码不允许显示任何"谢谢"消息.是否有"AfterRender"事件或类似的页面,我可以移动此下载代码并为页面提供向用户呈现"谢谢"消息的机会?毕竟,我真的很感谢他们,所以我想表达这一点.