2010-11-03 47 views

回答

0

file_get_contents()手冊頁提供了一個完整的工作示例。

如果遇到問題,可以提出具體問題。

1

如果你想下載一個簡單的文本文件,可以使用文件(),或file_get_contents()函數:

file('http://url/to/file.txt') will return an array of lines 
file_get_contents('http://url/to/file.txt') will return the file as a string 

或者,當數據類型是二進制的,例如,你可以使用下面的代碼片段,發現在php.net

<?php 
$filename = "/usr/local/something.txt"; // This can also be an url to an external file 
$handle = fopen($filename, "rb"); 
$contents = stream_get_contents($handle); 
fclose($handle); 
?> 

現在你可以例如寫內容到一個文件中。

希望這會有所幫助。

[編輯]道歉,我貼錯了片段,這應該是一個

0

只是要使用PHP複製功能的權利:

if (!copy('http://www.example.com/file.jpg', '/path/to/dir/newfile.jpg')) 
{ 
    echo "failed to copy $file...\n"; 
}