【问题标题】:Transfer files from server to server from urls in a text file从文本文件中的 url 将文件从服务器传输到服务器
【发布时间】:2016-02-23 13:52:36
【问题描述】:

您好,我想将文件从保存在文本文件中的 url 从一台服务器传输到另一台服务器。我正在使用共享的 linux 主机。 目前,此代码适用于从单个 url 传输文件。但我想从一个文本文件中加载许多 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 中屏蔽。 有人可以帮忙吗?

【问题讨论】:

  • 你必须创建一个数组并使用foreach
  • 你能告诉我怎么做吗
  • 将文本文件中的每一行一一读取,然后解析。

标签: php text server transfer


【解决方案1】:

这是一个非常简单的示例,您可以如何做到这一点。

    $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";
        }
    }

【讨论】:

  • 谢谢,但我说的是几十个 url,它们会在一个文本文件中。
  • 在这种情况下,您没有提供有关该问题的足够信息。必须有某种结构。无论如何,您都坚持使用数组。你如何用信息填充这些数组是另一回事
猜你喜欢
  • 2011-02-04
  • 2012-12-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-24
  • 1970-01-01
  • 2012-12-06
相关资源
最近更新 更多