什么是简单的PHP文件下载脚本?

时间:2010-11-05 07:11:00

标签: php web ftp

我昨天刚刚买了一个网域(cryptum.net),我打算上传一些文件。我的问题是我没有一个好的PHP5下载脚本。我只想要一个简单的脚本,将文件保存到用户下载文件夹。这些文件位于网站ftp服务器上。这是我到目前为止所拥有的 -

<?php
$conn = ftp_connect("ftp://username@cryptum.net") or die("Could not connect");
ftp_login($conn,"username","password");

//download script goes here

ftp_close($conn);
?>

2 个答案:

答案 0 :(得分:1)

<?php
//...
//download script goes here
ftp_get ($conn, '/destination/on/my/hardDrive', '/file/to/download'); 
//...
?>

你可以用php-curl代替......

答案 1 :(得分:1)

另一个非常优雅的解决方案,它使用PHP强大的流功能:

<?php
$ftp_server  = 'ftp://username:password@cryptum.net/';
$remote_file = 'user/directory/file';
$local_file  = '/path/to/the/local/file';

file_put_contents($local_file, file_get_contents($ftp_server.$destination_file));
相关问题