2

アップロードされたファイルをあるサーバーから別のサーバーに移動する方法を実装するのを手伝ってくれる人はいますか

move_uploaded_file() 関数について話しているのではありません。

例えば、

画像がhttp://example.comからアップロードされた場合

http://image.example.comに移動するにはどうすればよいですか

可能ですよね?別の投稿やプットリクエストを送信することによってではありませんか?

4

1 に答える 1

3

アップロードされたファイルを一時的な場所に移動し、任意の FTP アカウントにプッシュします。

$tempName = tempnam(sys_get_temp_dir(), 'upload');
move_uploaded_file($_FILES["file"]["tmpname"], $tempName);

$handle = fopen("ftp://user:password@example.com/somefile.txt", "w");
fwrite($handle, file_get_contents($uploadedFile));
fclose($handle);
unlink($tempName);

実際には、 の部分も必要ありませんmove_uploaded_file。アップロードされたファイルを取得し、その内容を で開いたファイルに書き込むだけで十分ですfopen。で URL を開く方法の詳細についてfopenは、php-documentationを参照してください。ファイルのアップロードの詳細については、PHP マニュアルのFile-Upload-Sectionを参照してください。

[編集]file_get_contentsコード例に追加

[編集]短い例

$handle = fopen("ftp://user:password@example.com/somefile.txt", "w");
fwrite($handle, file_get_contents($_FILES["file"]["tmpname"]);
fclose($handle);
// As the uploaded file has not been moved from the temporary folder 
// it will be deleted from the server the moment the script is finished.
// So no cleaning up is required here.
于 2013-06-06T05:47:37.783 に答える