1

私が本当にやりたいことは:

  • ユーザーはhtmlページからスクリプトにアップロードします
  • スクリプトはログインしてリンクを返します

まあ、すべてはカールとマルチパート投稿によるファイルの受け入れの助けを借りて簡単に行うことができます。

しかし、ここでの問題は、すべてのアップロードが完了した後、curlを介してサーバーから別のサーバーにファイルのアップロードを開始することです:(これには長いプロセスが必要です。ユーザーがファイルをアップロードするようにすることは可能かどうか疑問に思いました。ファイルをダウンロードするように、データをチャンクで送信し続けます

これがphpでも可能かどうかはわかりません。そうでない場合は、これを可能にする他の方法

4

1 に答える 1

4

これは、cURLを使用して実行できます。

// Open a stream so that we stream the image download
$localFile = $_FILES[$fileKey]['tmp_name'];

$stream = fopen($localFile, 'r');

// Create a curl handle to upload to the file server     
$ch = curl_init($fileServer);
// Send a PUT request
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
// Let curl know that we are sending an entity body
curl_setopt($ch, CURLOPT_UPLOAD, true);
// Let curl know that we are using a chunked transfer encoding
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Transfer-Encoding: chunked'));
// Use a callback to provide curl with data to transmit from the stream
curl_setopt($ch, CURLOPT_READFUNCTION, function($ch, $fd, $length) use ($stream) {
    return fread($stream, $length) ? '';
});

curl_exec($ch);
于 2012-10-02T14:52:37.770 に答える