簡體   English   中英

通過文本文件中的URL在服務器之間傳輸文件

[英]Transfer files from server to server from urls in a text file

嗨,我想將文件從保存在文本文件中的URL從一台服務器傳輸到另一台服務器。 我正在使用共享的Linux主機。 當前,此代碼可用於從單個URL傳輸文件。 但我想從文本文件中加載許多網址。

/* Source File URL */
$remote_file_url = 'http://origin-server-url/files.mp4';

/* New file name and path for this file */
$local_file = 'files.mp4';

/* Copy the file from source url to server */
$copy = copy( $remote_file_url, $local_file );

/* Add notice for success/failure */
if( !$copy ) {
echo "Doh! failed to copy $file...\n";
}
else{
echo "WOOT! success to copy $file...\n";
}

並且文件名和擴展名應從每個URL中屏蔽。 有人可以幫忙。

這是一個非常簡單的示例,您如何執行此操作。

    $remoteFileUrls = [
        'File 1' => 'http://origin-server-url/files.mp4',
        'File 2' => 'http://origin-server-url/files.mp4',
        'File 3' => 'http://origin-server-url/files.mp4',
        'File 4' => 'http://origin-server-url/files.mp4'
    ];

    $localFileUrls = [
        'File 1' => 'files.mp4',
        'File 2' => 'files.mp4',
        'File 3' => 'files.mp4',
        'File 4' => 'files.mp4'
    ];

    foreach($remoteFileUrls as $key => $remoteUrl){
        /* Copy the file from source url to server */
        $copy = copy( $remoteUrl, $localFileUrls[$key] );

        /* Add notice for success/failure */
        if( $copy ) {
            echo "Success\n";
        }
        else{
            echo "Failed\n";
        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM