2013-05-13 7 views
7

원격 서버에 제한없이 다운로드 할 수있는 파일이 있다고 가정 해 봅시다. 당신은 당신의 브라우저에있는 파일에 대한 직접 링크를 넣을 수 있으며 파일을 다운로드합니다. 예를 들어 http://www.remotesite.com/video.avi은 브라우저에 해당 파일을 다운로드하라는 메시지를 표시합니다. PHP를 사용하면 파일을 가져 와서 내 PC에 파일을 다운로드하지 않고 로컬 서버에 업로드하는 가장 좋은 방법은 무엇입니까? 파일 업로드 양식에 URL을 넣으면 phpBB가 어떻게됩니까? 필요한 코드의 예를 들어 주시면 감사하겠습니다. 감사합니다원격 서버에서 파일을 가져 와서 PHP를 사용하여 로컬 서버에 복사하는 가장 좋은 방법

+0

http://php.net/manual/en/function.file- get-contents.php –

답변

23

그냥 사용 읽고 브라우저 다운로드없이 파일을 쓸 수 copy

$source = "http://www.remotesite.com/video.avi"; 
$dest = "video.avi"; 
copy($source, $dest); 
+1

는'file_get' 및'file_put'보다 차갑게 들립니다 :) –

+1

해시 태그 간명 –

3
$remote_file_contents = file_get_contents('http://remote_url/file/with.extension'); 
//Get the contents 

$local_file_path = 'your/local/path/to/the/file/with.extension'; 

file_put_contents($local_file_path, $remote_file_contents); 
//save the contents of the remote file 
+0

http://www.php.net/manual/en/function.file-put-contents.php –

2

당신은

<?php 

$file = 'http://www.remotesite.com/video.avi'; 

// read the file from remote location 
$current = file_get_contents($file); 

// create new file name 
$name = "path/to/folder/newname.avi"; 

// Write the contents back to the file 
file_put_contents($file, $current);