Php 从FTP传输文件并允许用户同时下载

Php 从FTP传输文件并允许用户同时下载,php,ftp,Php,Ftp,我正在创建一个备份系统,在这个系统中,备份将自动生成,因此我将在不同的服务器上存储备份,但是当我要下载它们时,我希望链接是一次性链接,这并不难做到,然而,为了保证安全,我考虑将文件存储在另一台服务器上,使其无法通过http访问 因此,我要做的是通过ftp连接,将文件下载到主服务器,然后将其呈现以供下载并删除,但是如果备份很大,这将花费很长时间,有没有一种方法可以从ftp流式传输文件,而不显示下载文件的人的实际位置,而不将其存储在服务器上 下面是一个非常基本的示例,使用。它指定了一个读取回调,当可

我正在创建一个备份系统,在这个系统中,备份将自动生成,因此我将在不同的服务器上存储备份,但是当我要下载它们时,我希望链接是一次性链接,这并不难做到,然而,为了保证安全,我考虑将文件存储在另一台服务器上,使其无法通过http访问


因此,我要做的是通过ftp连接,将文件下载到主服务器,然后将其呈现以供下载并删除,但是如果备份很大,这将花费很长时间,有没有一种方法可以从ftp流式传输文件,而不显示下载文件的人的实际位置,而不将其存储在服务器上

下面是一个非常基本的示例,使用。它指定了一个读取回调,当可以从FTP读取数据时,将调用该回调,并将数据输出到浏览器,以便在与备份服务器进行FTP事务时同时下载到客户端

这是一个非常基本的exmaple,您可以对其进行扩展

<?php

// ftp URL to file
$url = 'ftp://ftp.mozilla.org/pub/firefox/nightly/latest-firefox-3.6.x/firefox-3.6.29pre.en-US.linux-i686.tar.bz2';

// init curl session with FTP address
$ch = curl_init($url);

// specify a callback function for reading data
curl_setopt($ch, CURLOPT_READFUNCTION, 'readCallback');

// send download headers for client
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename="backup.tar.bz2"');

// execute request, our read callback will be called when data is available
curl_exec($ch);


// read callback function, takes 3 params, the curl handle, the stream to read from and the maximum number of bytes to read    
function readCallback($curl, $stream, $maxRead)
{
    // read the data from the ftp stream
    $read = fgets($stream, $maxRead);

    // echo the contents just read to the client which contributes to their total download
    echo $read;

    // return the read data so the function continues to operate
    return $read;
}

这里是一个非常基本的示例。它指定了一个读取回调,当可以从FTP读取数据时,将调用该回调,并将数据输出到浏览器,以便在与备份服务器进行FTP事务时同时下载到客户端

这是一个非常基本的exmaple,您可以对其进行扩展

<?php

// ftp URL to file
$url = 'ftp://ftp.mozilla.org/pub/firefox/nightly/latest-firefox-3.6.x/firefox-3.6.29pre.en-US.linux-i686.tar.bz2';

// init curl session with FTP address
$ch = curl_init($url);

// specify a callback function for reading data
curl_setopt($ch, CURLOPT_READFUNCTION, 'readCallback');

// send download headers for client
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename="backup.tar.bz2"');

// execute request, our read callback will be called when data is available
curl_exec($ch);


// read callback function, takes 3 params, the curl handle, the stream to read from and the maximum number of bytes to read    
function readCallback($curl, $stream, $maxRead)
{
    // read the data from the ftp stream
    $read = fgets($stream, $maxRead);

    // echo the contents just read to the client which contributes to their total download
    echo $read;

    // return the read data so the function continues to operate
    return $read;
}

这些是内部备份吗?谁在下载?这些是内部备份吗?谁在下载?