If you need to copy a file from any website into yours you can use following function:
function getUrlContents($url)
{
$url_parsed = parse_url($url);
$host = $url_parsed["host"];
if ($url == '' || $host == '') {
return false;
}
$port = 80;
$path = (empty($url_parsed["path"]) ? '/' : $url_parsed["path"]);
$path.= (!empty($url_parsed["query"]) ? '?'.$url_parsed["query"] : '');
$out = "GET $path HTTP/1.0\r\nHost: $host\r\nConnection: Close\r\n\r\n";
$fp = fsockopen($host, $port, $errno, $errstr, 30);
fwrite($fp, $out);
$headers = '';
$content = '';
$buf = '';
$isBody = false;
while (!feof($fp) and !$isBody) {
$buf = fgets($fp, 1024);
if ($buf == "\r\n" ) {$isBody = true;}
else{$headers .= $buf;}
}
$file1 = fopen(basename($url_parsed["path"]), 'w');
$bytes=stream_copy_to_stream($fp,$file1);
fclose($fp);
return $bytes;
}