Hello All,
Is there a way to download files in case curl extension is not available or has been disabled?
Hello All,
Is there a way to download files in case curl extension is not available or has been disabled?
You can get the content of a remote file using:
<?php
$file_content = file_get_contents('http://www.the-site.com/file.txt');
?>
This works too. Though you must have sockets enabled.
function getcontent($server, $file,$port=80)
{
$cont = "";
$ip = gethostbyname($server);
$fp = fsockopen($ip, $port);
if (!$fp)
{
return "Unknown";
}
else
{
$com = "GET $file HTTP/1.1\r\nAccept: */*\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)\r\nHost: $server:$port\r\nConnection: Keep-Alive\r\n\r\n";
fputs($fp, $com);
while (!feof($fp))
{
$cont .= fread($fp, 500);
}
fclose($fp);
$cont = substr($cont, strpos($cont, "\r\n\r\n") + 4);
return $cont;
}
}
Usage:
getcontent('google.com', '/intl/en_ALL/images/logo.gif');