发送文件给客户端 [英] send a file to client

查看:187
本文介绍了发送文件给客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过Php在服务器上写一个文本文件,并让客户端下载该文件。

I want to write a text file in the server through Php, and have the client to download that file.

我该怎么做?

客户端本质上应该能够从服务器下载文件。

Essentially the client should be able to download the file from the server.

推荐答案

除了已发布的数据之外,还有一个标题可能需要尝试。

In addition to the data already posted, there is a header you might want to try.

它只是一个的建议,它的意图如何被处理,用户代理可以选择忽略它,并只显示文件窗口如果它知道如何:

Its only a suggestion to how its meant to be handled, and the user agent can chose to ignore it, and simply display the file in the window if it knows how:

<?php

 header('Content-Type: text/plain');         # its a text file
 header('Content-Disposition: attachment');  # hit to trigger external mechanisms instead of inbuilt

请参阅 Rfc2183 有关Content-Disposition标题的更多信息。

See Rfc2183 for more on the Content-Disposition header.

这篇关于发送文件给客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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