从站点PHP下载文件 [英] Download file from site PHP

查看:107
本文介绍了从站点PHP下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将在PHP脚本中了解命令以获取输出并从我的站点保存文件。
谢谢

I would to know the command in a PHP script to get in output and save a file from my site. Thanks

推荐答案

请参阅这里,以了解如何强制输出php脚本进行下载。

See here for a good description of how to force the output of a php script to be a download.

其基本原理是:

// Set headers
 header("Cache-Control: public");
 header("Content-Description: File Download");
 header("Content-Disposition: attachment; filename=" + $filename);
 header("Content-Type: application/zip"); // or whatever the mime-type is
                                          // for the file you want to download
 header("Content-Transfer-Encoding: binary");

 // Read the file from disk
 readfile($full_path_to_file);

作为添加(由Gordon的评论提供),请参阅php文档的第一个示例 here

As an addition (provided by Gordon's comment), see the 1st example on the php documentation here

这篇关于从站点PHP下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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