开发者

Bast way to move file from server to server in PHP

I have sites where stored some xml files开发者_如何转开发, and I want to download to our server, we don't have ftp connection, so we can download through http. I always used file(url) is there any better way to download files through php


If you can access them via http, file() (which reads the file into an array) and file_get_contents() (which reads content into a string) are perfectly fine provided that the wrappers are enabled.


Using CURL could also be a nice option:

// create a new CURL resource 
$ch = curl_init(); 

// set URL and other appropriate options 
curl_setopt($ch, CURLOPT_URL, "http://www.server.com/file.zip"); 
curl_setopt($ch, CURLOPT_HEADER, false); 
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

set_time_limit(300); # 5 minutes for PHP 
curl_setopt($ch, CURLOPT_TIMEOUT, 300); # and also for CURL 

$outfile = fopen('/mysite/file.zip', 'wb'); 
curl_setopt($ch, CURLOPT_FILE, $outfile); 

// grab file from URL 
curl_exec($ch); 
fclose($outfile); 

// close CURL resource, and free up system resources 
curl_close($ch); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜