2

バックアップが自動的に生成されるバックアップ システムを作成しているので、別のサーバーにバックアップを保存しますが、それらをダウンロードするときは、リンクを 1 回限りのリンクにしたいのですが、これは難しくありません。ただし、これを安全にするために、ファイルを保存して、他のサーバーのhttp経由でアクセスできないようにすることを考えていました。

したがって、私が行うことは、ftp経由で接続し、ファイルをメインサーバーにダウンロードしてから、ダウンロード用に提示して削除しますが、バックアップが大きい場合、これには時間がかかります。表示せずにFTPからストリーミングする方法はありますか実際の場所をダウンロードしていて、サーバーに保存していない人?

4

1 に答える 1

0

これは、 cURLを使用した非常に基本的な例です。これは、データが FTP から読み取れるようになったときに呼び出される読み取りコールバックを指定し、データをブラウザーに出力して、バックアップ サーバーで FTP トランザクションが行われている間にクライアントへの同時ダウンロードを提供します。

これは、拡張できる非常に基本的な例です。

<?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;
}

オプションの詳細については、curl_setopt()を参照してください。CURLOPT_READFUNCTION

于 2012-04-22T22:34:54.110 に答える