2016-02-23 148 views
0

您好我想從文件中保存的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中屏蔽掉。 有人可以幫忙。

+0

你必須創建一個數組和使用的foreach – user2831723

+0

你能告訴我該怎麼辦呢 – Cloud

+0

通過一個閱讀的文本文件一每一行,並對其進行分析,然後。 –

回答

0

這是一個非常簡單的例子,你可以做到這一點。

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

謝謝,但我正在談論數十個網址,這將在一個文本文件中。 – Cloud

+0

在這種情況下,您尚未提供有關此問題的足夠信息。必須有某種結構。無論如何,你都堅持使用數組。如何用信息填充這些數組是另一回事 – user2831723

相關問題