2012-08-12 117 views
0

我有一个运行在apache服务器上的php页面和一个存储文件的ftp服务器,位于不同的机器上。 ftp服务器不能从外部访问。PHP从FTP服务器获取文件并显示保存文件对话框

我希望当用户点击我的网页上的一个按钮时,PHP服务器连接到FTP服务器,检索一个文件,并显示另存为对话框,以便用户可以存储它。

任何帮助表示赞赏, 拉杜

+0

我们需要的代码。但是,在PHP的'readfile'手册中,有一个很好的小脚本。 – 2012-08-12 11:26:01

+0

你已经看过[PHP的FTP功能](http://php.net/ftp)吗? – Gumbo 2012-08-12 11:26:32

+0

你需要什么代码?我只调用ftp来检索文件,但我不知道如何在不保存文件的情况下打开保存文件对话框。 – 2012-08-12 11:28:57

回答

1

在这里你去。在写的download.php这

$file = 'location/of/your/file.ext'; 
readfile($file); 
header("Cache-Control: public"); 
header("Content-Description: File Transfer"); 
header("Content-Disposition: attachment; filename=".$file); 
header("Content-Type: application/zip"); 
header("Content-Transfer-Encoding: binary"); 

这应该工作:)